@@ -22,10 +22,12 @@ If you need support using AfterShip products, please contact
[email protected]
22
22
- [ Endpoints] ( #endpoints )
23
23
- [ /trackings] ( #trackings )
24
24
- [ /couriers] ( #couriers )
25
+ - [ /courier-connections] ( #courier-connections )
25
26
- [ /estimated-delivery-date] ( #estimated-delivery-date )
26
27
- [ Help] ( #help )
27
28
- [ License] ( #license )
28
29
30
+
29
31
## Before you begin
30
32
31
33
Before you begin to integrate:
@@ -38,19 +40,20 @@ Before you begin to integrate:
38
40
39
41
Each SDK version is designed to work with a specific API version. Please refer to the table below to identify the supported API versions for each SDK version, ensuring you select the appropriate SDK version for the API version you intend to use.
40
42
41
- | SDK Version | Supported API Version | Branch |
42
- | ----------- | --------------------- | ------------------------------------------------------------- |
43
- | 12.x.x | 2025-01 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2025-01 |
44
- | 11.x.x | 2024-10 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-10 |
45
- | 10.x.x | 2024-07 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-07 |
46
- | 9.x.x | 2024-04 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-04 |
47
- | 8.x.x | 2023-10 | https://github.com/AfterShip/aftership-sdk-nodejs |
48
- | <=7.x.x | Legacy API | https://github.com/AfterShip/aftership-sdk-nodejs |
43
+ | SDK Version | Supported API Version | Branch |
44
+ | --- | --- | --- |
45
+ | 13.x.x | 2025-04 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2025-04 |
46
+ | 12.x.x | 2025-01 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2025-01 |
47
+ | 11.x.x | 2024-10 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-10 |
48
+ | 10.x.x | 2024-07 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-07 |
49
+ | 9.x.x | 2024-04 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-04 |
50
+ | 8.x.x | 2023-10 | https://github.com/AfterShip/aftership-sdk-nodejs |
51
+ | <=7.x.x | Legacy API | https://github.com/AfterShip/aftership-sdk-nodejs |
52
+
49
53
50
54
## Quick Start
51
55
52
56
### Installation
53
-
54
57
``` bash
55
58
npm install --save @aftership/tracking-sdk
56
59
```
@@ -61,7 +64,7 @@ Create AfterShip instance with options
61
64
62
65
| Name | Type | Required | Description |
63
66
| ---------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
64
- | api_key | string | ✔ | Your AfterShip API key |
67
+ | api_key | string | ✔ | Your AfterShip API key |
65
68
| auth_type | enum | | Default value: ` AuthType.API_KEY ` <br > AES authentication: ` AuthType.AES ` <br > RSA authentication: ` AuthType.RSA ` |
66
69
| api_secret | string | | Required if the authentication type is ` AuthType.AES ` or ` AuthType.RSA ` |
67
70
| domain | string | | AfterShip API domain. Default value: https://api.aftership.com |
@@ -74,43 +77,44 @@ Create AfterShip instance with options
74
77
75
78
``` javascript
76
79
// Step 1: Require the AfterShip client
77
- import { AfterShip } from " @aftership/tracking-sdk" ;
80
+ import {AfterShip } from ' @aftership/tracking-sdk' ;
78
81
// or
79
82
// const {AfterShip} = require('@aftership/tracking-sdk');
80
83
84
+
81
85
// Step 2: Initialize the client object
82
- const aftership = new AfterShip ({ api_key: " YOUR_API_KEY" });
86
+ const aftership = new AfterShip ({api_key: ' YOUR_API_KEY' });
83
87
84
88
// Step 3: Create the request object
85
89
const createTrackingRequestBody = {
86
- tracking_number: " <tracking_number>" ,
87
- slug: " <slug>" ,
90
+ tracking_number: ' <tracking_number>' ,
91
+ slug: ' <slug>'
88
92
};
89
93
90
94
// Step 4: Make the request
91
- aftership .tracking
92
- .createTracking (createTrackingRequestBody)
93
- .then ((tracking ) => console .log (tracking))
94
- .catch ((error ) => console .log (error));
95
+ aftership .tracking .createTracking (createTrackingRequestBody)
96
+ .then (tracking => console .log (tracking))
97
+ .catch (error => console .log (error));
95
98
```
96
99
97
100
## Rate Limiter
98
101
99
- See the [ Rate Limit] ( https://www.aftership.com/docs/tracking/2024-10 /quickstart/rate-limit ) to understand the AfterShip rate limit policy.
102
+ See the [ Rate Limit] ( https://www.aftership.com/docs/tracking/2025-04 /quickstart/rate-limit ) to understand the AfterShip rate limit policy.
100
103
101
104
## Error Handling
102
105
103
106
The SDK will return an error object when there is any error during the request, with the following specification:
104
107
105
- | Name | Type | Description |
106
- | ---------------- | ------ | ------------------------------ |
107
- | message | string | Detail message of the error |
108
- | code | enum | Error code enum for API Error. |
109
- | meta_code | number | API response meta code. |
110
- | status_code | number | HTTP status code. |
111
- | response_body | string | API response body. |
108
+ | Name | Type | Description |
109
+ | --------------- | ------ | ------------------------------ |
110
+ | message | string | Detail message of the error |
111
+ | code | enum | Error code enum for API Error. |
112
+ | meta_code | number | API response meta code. |
113
+ | status_code | number | HTTP status code. |
114
+ | response_body | string | API response body. |
112
115
| response_headers | object | API response header. |
113
116
117
+
114
118
### Error List
115
119
116
120
| code | meta_code | status_code | message |
@@ -144,8 +148,9 @@ The AfterShip instance has the following properties which are exactly the same a
144
148
145
149
- courier - Get a list of our supported couriers.
146
150
- tracking - Create trackings, update trackings, and get tracking results.
151
+ - courier-connection - Create courier connections, update courier connections, and get courier connections results.
147
152
- estimated-delivery-date - Get estimated delivery date for your order.
148
-
153
+
149
154
### /trackings
150
155
151
156
** POST** /trackings
@@ -164,92 +169,128 @@ const payload = {
164
169
};
165
170
166
171
aftership .tracking
167
- .createTracking (payload)
168
- .then ((result ) => console .log (result))
169
- .catch ((e ) => console .log (e));
172
+ .createTracking (payload)
173
+ .then ((result ) => console .log (result))
174
+ .catch ((e ) => console .log (e));
170
175
```
171
176
172
177
** DELETE** /trackings/: id
173
178
174
179
``` javascript
175
180
aftership .tracking
176
- .deleteTrackingById (" <tracking_id>" )
177
- .then ((result ) => console .log (result))
178
- .catch ((e ) => console .log (e));
181
+ .deleteTrackingById (' <tracking_id>' )
182
+ .then ((result ) => console .log (result))
183
+ .catch ((e ) => console .log (e));
179
184
```
180
185
181
186
** GET** /trackings
182
187
183
188
``` javascript
184
189
aftership .tracking
185
- .getTrackings ({ limit: 10 , fields: " slug,tracking_number" })
186
- .then ((result ) => console .log (result))
187
- .catch ((e ) => console .log (e));
190
+ .getTrackings ({ limit: 10 , fields: ' slug,tracking_number' })
191
+ .then ((result ) => console .log (result))
192
+ .catch ((e ) => console .log (e));
188
193
```
189
194
190
195
** GET** /trackings/: id
191
196
192
197
``` javascript
193
198
aftership .tracking
194
- .getTrackingById (" <tracking_id>" )
195
- .then ((result ) => console .log (result))
196
- .catch ((e ) => console .log (e));
199
+ .getTrackingById (' <tracking_id>' )
200
+ .then ((result ) => console .log (result))
201
+ .catch ((e ) => console .log (e));
197
202
```
198
203
199
204
** PUT** /trackings/: id
200
205
201
206
``` javascript
202
207
aftership .tracking
203
- .updateTrackingById (" <tracking_id>" , { title: " New Title123" })
204
- .then ((result ) => console .log (result))
205
- .catch ((e ) => console .log (e));
208
+ .updateTrackingById (' <tracking_id>' ,{ title: ' New Title123' })
209
+ .then ((result ) => console .log (result))
210
+ .catch ((e ) => console .log (e));
206
211
```
207
212
208
213
** POST** /trackings/: id /retrack
209
214
210
215
``` javascript
211
216
aftership .tracking
212
- .retrackTrackingById (" <tracking_id>" )
213
- .then ((result ) => console .log (result))
214
- .catch ((e ) => console .log (e));
217
+ .retrackTrackingById (' <tracking_id>' )
218
+ .then ((result ) => console .log (result))
219
+ .catch ((e ) => console .log (e));
215
220
```
216
221
217
222
** POST** /trackings/: id /mark-as-completed
218
223
219
224
``` javascript
220
225
aftership .tracking
221
- .markTrackingCompletedById (" <tracking_id>" , { reason: " DELIVERED" })
222
- .then ((result ) => console .log (result))
223
- .catch ((e ) => console .log (e));
226
+ .markTrackingCompletedById (' <tracking_id>' , { reason: ' DELIVERED' })
227
+ .then ((result ) => console .log (result))
228
+ .catch ((e ) => console .log (e));
224
229
```
225
230
226
231
### /couriers
227
-
228
232
** GET** /couriers
229
233
230
234
``` javascript
231
235
aftership .courier
232
- . getUserCouriers ()
233
- .then (( result ) => console .log (result))
234
- .catch (( e ) => console .log (e));
236
+ . GetCouriers ()
237
+ .then (result => console .log (result))
238
+ .catch (e => console .log (e));
235
239
```
236
240
237
- ** GET** /couriers/all
241
+ ** POST** /couriers/detect
242
+
243
+ ``` js
244
+ aftership .courier
245
+ .detectCourier ({ tracking_number: ' <tracking_number>' })
246
+ .then (result => console .log (result))
247
+ .catch (e => console .log (e));
248
+ ```
249
+
250
+ ### /courier-connections
251
+ ** GET** /courier-connections
238
252
239
253
``` javascript
240
254
aftership .courier
241
- . getAllCouriers ()
242
- .then (( result ) => console .log (result))
243
- .catch (( e ) => console .log (e));
255
+ . getCourierConnections ()
256
+ .then (result => console .log (result))
257
+ .catch (e => console .log (e));
244
258
```
245
259
246
- ** POST** /couriers/detect
260
+ ** POST** /courier-connections
247
261
248
262
``` js
249
263
aftership .courier
250
- .detectCourier ({ tracking_number: " <tracking_number>" })
251
- .then ((result ) => console .log (result))
252
- .catch ((e ) => console .log (e));
264
+ .postCourierConnections ({courier_slug: " dhl-api" , credentials: {" api_key" : " <api_key>" }})
265
+ .then (result => console .log (result))
266
+ .catch (e => console .log (e));
267
+ ```
268
+
269
+ ** GET** /courier-connections/: id
270
+
271
+ ``` js
272
+ aftership .courier
273
+ .getCourierConnectionsById (" <courier_connection_id>" )
274
+ .then (result => console .log (result))
275
+ .catch (e => console .log (e));
276
+ ```
277
+
278
+ ** PATCH** /courier-connections/: id
279
+
280
+ ``` js
281
+ aftership .courier
282
+ .putCourierConnectionsById (" <courier_connection_id>" , {credentials: {" api_key" : " <api_key>" }})
283
+ .then (result => console .log (result))
284
+ .catch (e => console .log (e));
285
+ ```
286
+
287
+ ** DELETE** /courier-connections/: id
288
+
289
+ ``` js
290
+ aftership .courier
291
+ .deleteCourierConnectionsById (" <courier_connection_id>" )
292
+ .then (result => console .log (result))
293
+ .catch (e => console .log (e));
253
294
```
254
295
255
296
### /estimated-delivery-date
@@ -258,20 +299,33 @@ aftership.courier
258
299
259
300
``` javascript
260
301
const payload = {
261
- estimated_delivery_dates: [
262
- {
263
- slug: " <slug>" ,
264
- origin_address: { country: " <country>" },
265
- destination_address: { country: " <country>" },
266
- },
267
- ],
302
+ estimated_delivery_dates: [{
303
+ slug: ' <slug>' ,
304
+ origin_address: { country: ' <country>' },
305
+ destination_address: { country: ' <country>' },
306
+ }]
307
+ };
308
+ aftership .estimatedDeliveryDate
309
+ .predictBatch (payload)
310
+ .then (result => console .log (result))
311
+ .catch (e => console .log (e));
312
+ ```
313
+
314
+ ** POST** /estimated-delivery-date/predict
315
+
316
+ ``` javascript
317
+ const payload = {
318
+ slug: ' <slug>' ,
319
+ origin_address: { country: ' <country>' },
320
+ destination_address: { country: ' <country>' },
268
321
};
269
322
aftership .estimatedDeliveryDate
270
- . predictBatch (payload)
271
- .then (( result ) => console .log (result))
272
- .catch (( e ) => console .log (e));
323
+ . predict (payload)
324
+ .then (result => console .log (result))
325
+ .catch (e => console .log (e));
273
326
```
274
327
328
+
275
329
## Help
276
330
277
331
If you get stuck, we're here to help:
@@ -280,7 +334,6 @@ If you get stuck, we're here to help:
280
334
- Contact AfterShip official support via
[email protected]
281
335
282
336
## License
283
-
284
337
Copyright (c) 2025 AfterShip
285
338
286
- Licensed under the MIT license.
339
+ Licensed under the MIT license.
0 commit comments