1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "before": {
12 "format": "csv",
13 "data": "sku,price,stock\nA,19.9900,10\nB,25.00,4\nC,9.50,0\nD,12.00,2\n"
14 },
15 "after": {
16 "format": "json",
17 "data": [
18 {
19 "sku": "A",
20 "price": 19.99,
21 "stock": 10
22 },
23 {
24 "sku": "B",
25 "price": 29,
26 "stock": 4
27 },
28 {
29 "sku": "C",
30 "price": 9.5,
31 "stock": 0
32 },
33 {
34 "sku": "E",
35 "price": 15,
36 "stock": 5
37 }
38 ]
39 },
40 "keyFields": [
41 "sku"
42 ],
43 "fieldRules": {
44 "price": {
45 "type": "decimal"
46 },
47 "stock": {
48 "type": "decimal"
49 }
50 },
51 "snapshotsComplete": true
52};
53
54
55const run = await client.actor("mrtronson/typed-csv-json-diff").call(input);
56
57
58console.log('Results from dataset');
59console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
60const { items } = await client.dataset(run.defaultDatasetId).listItems();
61items.forEach((item) => {
62 console.dir(item);
63});
64
65