1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "cartsFile": {
12 "format": "json",
13 "content": "[{\"cart_id\": \"DEMO-1\", \"currency\": \"USD\", \"items\": [{\"sku\": \"A\", \"quantity\": 1, \"unit_price\": \"100.00\"}]}]"
14 },
15 "productCostsFile": {
16 "format": "json",
17 "content": "[{\"sku\": \"A\", \"currency\": \"USD\", \"unit_cost\": \"60.00\"}]"
18 },
19 "promotionRules": [
20 {
21 "id": "TENPCT",
22 "type": "percent",
23 "scope": "cart",
24 "value": "10"
25 },
26 {
27 "id": "TENUSD",
28 "type": "fixed",
29 "scope": "cart",
30 "value": "10"
31 },
32 {
33 "id": "SHIP",
34 "type": "free_shipping"
35 }
36 ],
37 "rulePriority": [
38 "TENPCT",
39 "TENUSD",
40 "SHIP"
41 ],
42 "scenarios": [
43 [
44 "TENPCT",
45 "TENUSD"
46 ],
47 [
48 "TENPCT",
49 "TENUSD",
50 "SHIP"
51 ]
52 ],
53 "shippingInputs": {
54 "DEMO-1": {
55 "revenue": "10",
56 "cost": "7",
57 "variable_cost": "3"
58 }
59 },
60 "roundingPolicy": {
61 "mode": "HALF_UP",
62 "decimals": 2
63 },
64 "marginThreshold": {
65 "type": "amount",
66 "value": "25"
67 },
68 "maxScenarios": 100
69};
70
71
72const run = await client.actor("afkdigital/newapi90-promotion-stacking-simulator").call(input);
73
74
75console.log('Results from dataset');
76console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
77const { items } = await client.dataset(run.defaultDatasetId).listItems();
78items.forEach((item) => {
79 console.dir(item);
80});
81
82