1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "items": [
12 {
13 "id": 1,
14 "name": " Trail Backpack ",
15 "price": "89.90",
16 "stock": 12,
17 "tags": [
18 "outdoor",
19 "bag"
20 ],
21 "seller": {
22 "name": "Nordic Gear",
23 "country": "NO"
24 },
25 "created": "2025-03-14T09:30:00Z"
26 },
27 {
28 "id": 2,
29 "name": "Camp Stove",
30 "price": "$45.00",
31 "stock": 0,
32 "tags": [
33 "outdoor",
34 "cooking"
35 ],
36 "seller": {
37 "name": "Fire & Co",
38 "country": "US"
39 },
40 "created": "2025-01-02T10:00:00Z"
41 },
42 {
43 "id": 3,
44 "name": "Wool Socks 10-pack",
45 "price": "24",
46 "stock": 150,
47 "tags": [],
48 "seller": {
49 "name": "Nordic Gear",
50 "country": "NO"
51 },
52 "created": "2025-02-20T08:15:00Z"
53 },
54 {
55 "id": 4,
56 "name": "Headlamp 300",
57 "price": "39.5",
58 "stock": 8,
59 "tags": [
60 "light"
61 ],
62 "seller": {
63 "name": "Fire & Co",
64 "country": "US"
65 },
66 "created": "2024-11-30T17:45:00Z"
67 },
68 {
69 "id": 5,
70 "name": " Water Bottle 1L",
71 "price": "12",
72 "stock": 40,
73 "tags": [
74 "bottle",
75 "steel"
76 ],
77 "seller": {
78 "name": "Nordic Gear",
79 "country": "NO"
80 },
81 "created": "2025-03-01T12:00:00Z"
82 },
83 {
84 "id": 6,
85 "name": "Rain Jacket",
86 "price": "129",
87 "stock": 5,
88 "tags": [
89 "clothing"
90 ],
91 "seller": {
92 "name": "Alpine Ltd",
93 "country": "CH"
94 },
95 "created": "2025-02-05T07:20:00Z"
96 }
97 ],
98 "operations": [
99 {
100 "op": "flatten",
101 "delimiter": "_",
102 "arrays": "join"
103 },
104 {
105 "op": "text",
106 "fields": [
107 "name"
108 ],
109 "action": "trim"
110 },
111 {
112 "op": "cast",
113 "types": {
114 "price": "number"
115 }
116 },
117 {
118 "op": "rename",
119 "mapping": {
120 "seller_name": "seller",
121 "seller_country": "country"
122 }
123 },
124 {
125 "op": "filter",
126 "where": {
127 "field": "stock",
128 "op": "gt",
129 "value": 0
130 }
131 },
132 {
133 "op": "add_column",
134 "column": "price_with_tax",
135 "expr": "round(price * 1.2, 2)"
136 },
137 {
138 "op": "add_column",
139 "column": "year",
140 "expr": "date_part(created, 'year')"
141 },
142 {
143 "op": "sort",
144 "by": [
145 "price:desc"
146 ]
147 },
148 {
149 "op": "select",
150 "fields": [
151 "id",
152 "name",
153 "price",
154 "price_with_tax",
155 "seller",
156 "country",
157 "tags",
158 "year"
159 ]
160 }
161 ],
162 "exports": [
163 "csv"
164 ]
165};
166
167
168const run = await client.actor("data-done-right/dataset-transform").call(input);
169
170
171console.log('Results from dataset');
172console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
173const { items } = await client.dataset(run.defaultDatasetId).listItems();
174items.forEach((item) => {
175 console.dir(item);
176});
177
178