1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "mappings": [
12 {
13 "id": "001",
14 "sourceUrl": "https://example.com/Old?campaign=Q3#section",
15 "expectedFinalUrl": "https://example.com/New/?campaign=Q3"
16 },
17 {
18 "id": "002",
19 "sourceUrl": "https://example.com/legacy",
20 "expectedFinalUrl": "https://example.com/current"
21 },
22 {
23 "id": "003",
24 "sourceUrl": "https://example.com/sale-old",
25 "expectedFinalUrl": "https://example.com/sale-new"
26 },
27 {
28 "id": "004",
29 "sourceUrl": "https://example.com/retired",
30 "expectedFinalUrl": "https://example.com/retired",
31 "expectedFinalStatus": 410
32 },
33 {
34 "id": "005",
35 "sourceUrl": "https://example.com/loop-a",
36 "expectedFinalUrl": "https://example.com/loop-final"
37 },
38 {
39 "id": "006",
40 "sourceUrl": "https://example.com/unreachable",
41 "expectedFinalUrl": "https://example.com/available"
42 },
43 {
44 "id": "007",
45 "sourceUrl": "https://example.com/missing",
46 "expectedFinalUrl": "https://example.com/missing"
47 }
48 ],
49 "traces": [
50 {
51 "mappingId": "001",
52 "steps": [
53 {
54 "url": "https://example.com/Old?campaign=Q3",
55 "status": 301,
56 "location": "/New/?campaign=Q3"
57 },
58 {
59 "url": "https://example.com/New/?campaign=Q3",
60 "status": 200
61 }
62 ]
63 },
64 {
65 "mappingId": "002",
66 "steps": [
67 {
68 "url": "https://example.com/legacy",
69 "status": 308,
70 "location": "/current"
71 },
72 {
73 "url": "https://example.com/current",
74 "status": 200
75 }
76 ]
77 },
78 {
79 "mappingId": "003",
80 "steps": [
81 {
82 "url": "https://example.com/sale-old",
83 "status": 302,
84 "location": "/home"
85 },
86 {
87 "url": "https://example.com/home",
88 "status": 200
89 }
90 ]
91 },
92 {
93 "mappingId": "004",
94 "steps": [
95 {
96 "url": "https://example.com/retired",
97 "status": 410
98 }
99 ]
100 },
101 {
102 "mappingId": "005",
103 "steps": [
104 {
105 "url": "https://example.com/loop-a",
106 "status": 301,
107 "location": "/loop-b"
108 },
109 {
110 "url": "https://example.com/loop-b",
111 "status": 301,
112 "location": "/loop-a"
113 }
114 ]
115 },
116 {
117 "mappingId": "006",
118 "steps": [],
119 "failure": "transport_error"
120 },
121 {
122 "mappingId": "007",
123 "steps": [
124 {
125 "url": "https://example.com/missing",
126 "status": 404
127 }
128 ]
129 }
130 ]
131};
132
133
134const run = await client.actor("h_murdock/redirect-release-qa").call(input);
135
136
137console.log('Results from dataset');
138console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
139const { items } = await client.dataset(run.defaultDatasetId).listItems();
140items.forEach((item) => {
141 console.dir(item);
142});
143
144