1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "steps": [
12 {
13 "actor": "nerolabs/dataset-filter-transform",
14 "label": "Keep the active Pro accounts",
15 "input": {
16 "data": [
17 {
18 "email": "ana@example.com",
19 "plan": "Pro",
20 "mrr": 49,
21 "active": true
22 },
23 {
24 "email": "ben@example.com",
25 "plan": "Starter",
26 "mrr": 19,
27 "active": true
28 },
29 {
30 "email": "cara@example.com",
31 "plan": "Pro",
32 "mrr": 99,
33 "active": false
34 },
35 {
36 "email": "dan@example.com",
37 "plan": "Pro",
38 "mrr": 149,
39 "active": true
40 }
41 ],
42 "filters": [
43 {
44 "field": "plan",
45 "operator": "equals",
46 "value": "Pro"
47 },
48 {
49 "field": "active",
50 "operator": "isTrue"
51 }
52 ],
53 "filterMode": "AND"
54 }
55 },
56 {
57 "actor": "nerolabs/dataset-aggregate-pivot",
58 "label": "Total the revenue by plan",
59 "input": {
60 "groupByFields": [
61 "plan"
62 ],
63 "aggregations": [
64 {
65 "field": "mrr",
66 "function": "sum",
67 "as": "totalMrr"
68 }
69 ]
70 }
71 }
72 ],
73 "dryRun": true
74};
75
76
77const run = await client.actor("nerolabs/actor-pipeline-runner").call(input);
78
79
80console.log('Results from dataset');
81console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
82const { items } = await client.dataset(run.defaultDatasetId).listItems();
83items.forEach((item) => {
84 console.dir(item);
85});
86
87