Class: AftershipAPI::TrackingApi

Inherits:
Object
  • Object
show all
Defined in:
lib/aftership-tracking-sdk/api/tracking.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ TrackingApi

Returns a new instance of TrackingApi.



9
10
11
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 9

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



7
8
9
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 7

def api_client
  @api_client
end

Instance Method Details

#create_tracking(body:, opts: {}) ⇒ Model::CreateTrackingResponse

Parameters:

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 99

def create_tracking(body:, opts: {})
  opts[:body] = body
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.create_tracking ...'
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings"
  method = :'POST'

  # query parameters
  query_params = opts[:query_params] || {}
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'Tracking'

  new_options = opts.merge(
    :operation => :"TrackingApi.create_tracking",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#create_tracking\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::CreateTrackingResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end

#delete_tracking_by_id(id:, opts: {}) ⇒ Model::DeleteTrackingByIdResponse

delete_tracking_by_id Delete a tracking.

Parameters:

  • id (String)

    tracking ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 248

def delete_tracking_by_id(id:, opts: {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.delete_tracking_by_id ...'
  end
  if id.nil? or id.to_s == ''
    raise ApiError.new(:error_code => BAD_REQUEST, :message => "id cannot be nil or empty")
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings/#{id}"
  method = :'DELETE'

  # query parameters
  query_params = opts[:query_params] || {}
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'Tracking'

  new_options = opts.merge(
    :operation => :"TrackingApi.delete_tracking_by_id",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#delete_tracking_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::DeleteTrackingByIdResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end

#get_tracking_by_id(id:, opts: {}) ⇒ Model::GetTrackingByIdResponse

get_tracking_by_id Get tracking results of a single tracking.

Parameters:

  • id (String)

    tracking ID

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts:):

  • :fields (String)

    List of fields to include in the response. Use comma for multiple values. Fields to include: ‘destination_postal_code`, `tracking_ship_date`, `tracking_account_number`, `tracking_key`, `origin_country_region`, `destination_country_region`, `destination_state`, `title`, `order_id`, `tag`, `checkpoints`

  • :lang (String)

    Translate checkpoint messages from the carrier’s provided language to the target language. Supported target languages include:</br>&nbsp;&nbsp;&nbsp;&nbsp;- English (en)</br>&nbsp;&nbsp;&nbsp;&nbsp;- French (fr)</br>&nbsp;&nbsp;&nbsp;&nbsp;- French Canadian (fr-CA)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Arabic (ar)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Bulgarian (bg)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Catalan (ca)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Croatian (hr)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Czech (cs)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Danish (da)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Dutch (nl)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Estonian (et)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Filipino (tl)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Finnish (fi)</br>&nbsp;&nbsp;&nbsp;&nbsp;- German (de)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Greek (el)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Hebrew (he)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Hindi (hi)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Hungarian (hu)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Indonesian (id)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Italian (it)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Japanese (ja)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Korean (ko)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Latvian (lv)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Lithuanian (lt)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Malay (ms)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Polish (pl)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Portuguese (pt)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Romanian (ro)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Russian (ru)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Serbian (sr)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Slovak (sk)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Slovenian (sl)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Spanish (es)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Swedish (sv)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Thai (th)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Turkish (tr)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Ukrainian (uk)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Vietnamese (vi)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Simplified Chinese (zh-Hans)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Traditional Chinese (zh-Hant)</br>&nbsp;&nbsp;&nbsp;&nbsp;- Norwegian (nb)</br>

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 147

def get_tracking_by_id(id:, opts: {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.get_tracking_by_id ...'
  end
  if id.nil? or id.to_s == ''
    raise ApiError.new(:error_code => BAD_REQUEST, :message => "id cannot be nil or empty")
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings/#{id}"
  method = :'GET'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'fields'] = opts[:'fields'] if !opts[:'fields'].nil?
  query_params[:'lang'] = opts[:'lang'] if !opts[:'lang'].nil?
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'Tracking'

  new_options = opts.merge(
    :operation => :"TrackingApi.get_tracking_by_id",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#get_tracking_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::GetTrackingByIdResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end

#get_trackings(opts: {}) ⇒ Model::GetTrackingsResponse

get_trackings Get tracking results of multiple trackings.<div style=“visibility:hidden; height: 0”></div>

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts:):

  • :cursor (String)

    A string representing the cursor value for the current page of results.

  • :limit (Integer)

    Number of trackings each page contain. (Default: 100, Max: 200)

  • :keyword (String)

    Search the content of the tracking record fields: ‘tracking_number`, `title`, `order_id`, `customers.name`, `custom_fields`, `customers.email`, `customers.phone_number`

  • :tracking_numbers (String)

    Tracking number of shipments. Use comma to separate multiple values (Example: RA123456789US,LE123456789US). Supports up to 50 tracking numbers.

  • :slug (String)

    Unique courier code Use comma for multiple values. (Example: dhl,ups,usps)

  • :transit_time (Integer)

    Total delivery time in days.- When the shipment is delivered: Transit time = Delivered date - Picked up date- When the shipment is not delivered: Transit time = Current date - Picked up dateValue as ‘null` for the shipment without pickup date.

  • :origin (String)

    Origin country/region of trackings. Use ISO Alpha-3 (three letters). Use comma for multiple values. (Example: USA,HKG)

  • :destination (String)

    Destination country/region of trackings. Use ISO Alpha-3 (three letters). Use comma for multiple values. (Example: USA,HKG)

  • :tag (String)

    Current status of tracking. Values include ‘Pending`, `InfoReceived`, `InTransit`, `OutForDelivery`, `AttemptFail`, `Delivered`, `AvailableForPickup`, `Exception`, `Expired` (See tag definition)

  • :created_at_min (String)

    Start date and time of trackings created. AfterShip only stores data of 120 days. Please make sure the value of the parameter is properly escaped in

  • :created_at_max (String)

    End date and time of trackings created. Please make sure the value of the parameter is properly escaped in

  • :updated_at_min (String)

    Start date and time of trackings updated. Please make sure the value of the parameter is properly escaped in

  • :updated_at_max (String)

    End date and time of trackings updated. Please make sure the value of the parameter is properly escaped in

  • :fields (String)

    List of fields to include in the response. Use comma for multiple values. Available options: ‘title`, `order_id`, `tag`, `checkpoints`. Example: `title,order_id`

  • :return_to_sender (String)

    Select return to sender, the value should be ‘true` or `false`, with optional comma separated.

  • :courier_destination_country_region (String)

    Destination country/region of trackings returned by courier. Use ISO Alpha-3 (three letters). Use comma for multiple values. (Example: USA,HKG)

  • :shipment_tags (String)

    Tags you added to your shipments to help categorize and filter them easily. Use a comma to separate multiple values (Example: a,b)

  • :order_id (String)

    A globally-unique identifier for the order. Use comma for multiple values.(Example: 6845a095a27a4caeb27487806f058add,4845a095a27a4caeb27487806f058abc)

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 35

def get_trackings(opts: {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.get_trackings ...'
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings"
  method = :'GET'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  query_params[:'keyword'] = opts[:'keyword'] if !opts[:'keyword'].nil?
  query_params[:'tracking_numbers'] = opts[:'tracking_numbers'] if !opts[:'tracking_numbers'].nil?
  query_params[:'slug'] = opts[:'slug'] if !opts[:'slug'].nil?
  query_params[:'transit_time'] = opts[:'transit_time'] if !opts[:'transit_time'].nil?
  query_params[:'origin'] = opts[:'origin'] if !opts[:'origin'].nil?
  query_params[:'destination'] = opts[:'destination'] if !opts[:'destination'].nil?
  query_params[:'tag'] = opts[:'tag'] if !opts[:'tag'].nil?
  query_params[:'created_at_min'] = opts[:'created_at_min'] if !opts[:'created_at_min'].nil?
  query_params[:'created_at_max'] = opts[:'created_at_max'] if !opts[:'created_at_max'].nil?
  query_params[:'updated_at_min'] = opts[:'updated_at_min'] if !opts[:'updated_at_min'].nil?
  query_params[:'updated_at_max'] = opts[:'updated_at_max'] if !opts[:'updated_at_max'].nil?
  query_params[:'fields'] = opts[:'fields'] if !opts[:'fields'].nil?
  query_params[:'return_to_sender'] = opts[:'return_to_sender'] if !opts[:'return_to_sender'].nil?
  query_params[:'courier_destination_country_region'] = opts[:'courier_destination_country_region'] if !opts[:'courier_destination_country_region'].nil?
  query_params[:'shipment_tags'] = opts[:'shipment_tags'] if !opts[:'shipment_tags'].nil?
  query_params[:'order_id'] = opts[:'order_id'] if !opts[:'order_id'].nil?
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'GetTrackingsResponseData'

  new_options = opts.merge(
    :operation => :"TrackingApi.get_trackings",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#get_trackings\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::GetTrackingsResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end

#mark_tracking_completed_by_id(id:, body:, opts: {}) ⇒ Model::MarkTrackingCompletedByIdResponse

Parameters:

Returns:



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 346

def mark_tracking_completed_by_id(id:, body:, opts: {})
  opts[:body] = body
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.mark_tracking_completed_by_id ...'
  end
  if id.nil? or id.to_s == ''
    raise ApiError.new(:error_code => BAD_REQUEST, :message => "id cannot be nil or empty")
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings/#{id}/mark-as-completed"
  method = :'POST'

  # query parameters
  query_params = opts[:query_params] || {}
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'Tracking'

  new_options = opts.merge(
    :operation => :"TrackingApi.mark_tracking_completed_by_id",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#mark_tracking_completed_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::MarkTrackingCompletedByIdResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end

#retrack_tracking_by_id(id:, opts: {}) ⇒ Model::RetrackTrackingByIdResponse

retrack_tracking_by_id Retrack an expired tracking. Max 3 times per tracking.

Parameters:

  • id (String)

    tracking id

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 296

def retrack_tracking_by_id(id:, opts: {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.retrack_tracking_by_id ...'
  end
  if id.nil? or id.to_s == ''
    raise ApiError.new(:error_code => BAD_REQUEST, :message => "id cannot be nil or empty")
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings/#{id}/retrack"
  method = :'POST'

  # query parameters
  query_params = opts[:query_params] || {}
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'Tracking'

  new_options = opts.merge(
    :operation => :"TrackingApi.retrack_tracking_by_id",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#retrack_tracking_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::RetrackTrackingByIdResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end

#update_tracking_by_id(id:, body:, opts: {}) ⇒ Model::UpdateTrackingByIdResponse

Parameters:

Returns:



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/aftership-tracking-sdk/api/tracking.rb', line 199

def update_tracking_by_id(id:, body:, opts: {})
  opts[:body] = body
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: TrackingApi.update_tracking_by_id ...'
  end
  if id.nil? or id.to_s == ''
    raise ApiError.new(:error_code => BAD_REQUEST, :message => "id cannot be nil or empty")
  end


  # resource path
  local_var_path = "/tracking/2025-07/trackings/#{id}"
  method = :'PUT'

  # query parameters
  query_params = opts[:query_params] || {}
  # header parameters
  header_params = opts[:header_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = 'Tracking'

  new_options = opts.merge(
    :operation => :"TrackingApi.update_tracking_by_id",
    :header_params => header_params,
    :query_params => query_params,
    :body => post_body,
    :return_type => return_type
  )

  data, _status_code, headers = @api_client.call_api(method, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: TrackingApi#update_tracking_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end

  resp = Model::UpdateTrackingByIdResponse.new
  resp.data = data
  resp.response_header = headers
  resp
end