1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "blueprints": [
12 {
13 "blueprint": {
14 "name": "Hourly Order Sync: HTTP to Iterator to Airtable",
15 "version": 1,
16 "metadata": {
17 "instant": false,
18 "version": 1,
19 "scheduling": {
20 "type": "indefinitely",
21 "interval": 3600
22 },
23 "scenario": {
24 "roundtrips": 1,
25 "maxErrors": 3,
26 "autoCommit": true
27 }
28 },
29 "flow": [
30 {
31 "id": 1,
32 "module": "http:ActionMakeRequest",
33 "version": 3,
34 "description": "Fetch Pending Orders Feed",
35 "mapper": {
36 "url": "https://orders.example.com/api/v1/pending",
37 "method": "GET",
38 "headers": [
39 {
40 "name": "Accept",
41 "value": "application/json"
42 }
43 ],
44 "parseResponse": true
45 },
46 "metadata": {
47 "designer": {
48 "x": 0,
49 "y": 0
50 }
51 }
52 },
53 {
54 "id": 2,
55 "module": "builtin:BasicFeeder",
56 "version": 1,
57 "description": "Iterate Pending Order Items",
58 "mapper": {
59 "array": "{{1.data.items}}"
60 },
61 "metadata": {
62 "designer": {
63 "x": 300,
64 "y": 0
65 }
66 }
67 },
68 {
69 "id": 3,
70 "module": "util:SetVariable2",
71 "version": 1,
72 "description": "Stamp Sync Date",
73 "filter": {
74 "name": "Only Active Orders",
75 "conditions": [
76 [
77 {
78 "a": "{{2.status}}",
79 "o": "TEXT_EQUAL",
80 "b": "active"
81 }
82 ]
83 ]
84 },
85 "mapper": {
86 "name": "syncedDate",
87 "value": "{{formatDate(now; \"YYYY-MM-DD\")}}"
88 },
89 "metadata": {
90 "designer": {
91 "x": 600,
92 "y": 0
93 }
94 }
95 },
96 {
97 "id": 4,
98 "module": "airtable:ActionCreateRecord",
99 "version": 3,
100 "description": "Create Airtable Order Record",
101 "mapper": {
102 "base": "appOrderBase001",
103 "table": "Orders",
104 "fields": {
105 "ExternalId": "{{2.id}}",
106 "CustomerName": "{{ifempty(2.name; \"Unknown\")}}",
107 "SyncedOn": "{{3.syncedDate}}"
108 }
109 },
110 "metadata": {
111 "designer": {
112 "x": 900,
113 "y": 0
114 }
115 }
116 },
117 {
118 "id": 5,
119 "module": "builtin:BasicAggregator",
120 "version": 1,
121 "description": "Aggregate Created Airtable Records",
122 "parameters": {
123 "sourceModule": 2
124 },
125 "mapper": {
126 "externalId": "{{2.id}}",
127 "airtableId": "{{4.id}}"
128 },
129 "metadata": {
130 "designer": {
131 "x": 1200,
132 "y": 0
133 }
134 }
135 },
136 {
137 "id": 6,
138 "module": "slack:ActionPostMessage",
139 "version": 1,
140 "description": "Post Hourly Batch Summary",
141 "mapper": {
142 "channel": "#ops-sync",
143 "text": "Synced {{length(5.array)}} active orders to Airtable on {{formatDate(now; \"YYYY-MM-DD\")}}"
144 },
145 "metadata": {
146 "designer": {
147 "x": 1500,
148 "y": 0
149 }
150 }
151 }
152 ]
153 }
154 }
155 ],
156 "monthlyRuns": 1000
157};
158
159
160const run = await client.actor("bodacious_mistral/make-to-cloudflare-analyzer").call(input);
161
162
163console.log('Results from dataset');
164console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
165const { items } = await client.dataset(run.defaultDatasetId).listItems();
166items.forEach((item) => {
167 console.dir(item);
168});
169
170