This library allows you to quickly and easily use the AfterShip Tracking API via Ruby.
For updates to this library, see our GitHub release page.
If you need support using AfterShip products, please contact support@aftership.com.
Before you begin to integrate:
- Create an AfterShip account.
- Create an API key.
- Install Ruby version Ruby 2.7 or later.
- SDK Version:
- API Version: 2025-07
gem install aftership-tracking-sdkOr add a line to your Gemfile
gem 'aftership-tracking-sdk', '~> 13.0.0'Create AfterShip instance with options
| Name | Type | Required | Description |
|---|---|---|---|
| api_key | string | ✔ | Your AfterShip API key |
| auth_type | enum | Default value: AuthType.API_KEY AES authentication: AuthType.AES RSA authentication: AuthType.RSA |
|
| api_secret | string | Required if the authentication type is AuthType.AES or AuthType.RSA |
|
| domain | string | AfterShip API domain. Default value: https://api.aftership.com | |
| user_agent | string | User-defined user-agent string, please follow RFC9110 format standard. | |
| proxy | string | HTTP proxy URL to use for requests. Default value: null Example: http://192.168.0.100:8888 |
|
| max_retry | number | Number of retries for each request. Default value: 2. Min is 0, Max is 10. | |
| timeout | number | Timeout for each request in milliseconds. |
require 'aftership-tracking-sdk'
AftershipAPI.configure do |config|
config.as_api_key = "YOUR_API_KEY"
end
begin
response = AftershipAPI::Tracking.get_tracking_by_id(id:"valid_value", )
p response
rescue AftershipAPI::ApiError => e
p e.message
endSee the Rate Limit to understand the AfterShip rate limit policy.
The SDK will return an error object when there is any error during the request, with the following specification:
| Name | Type | Description |
|---|---|---|
| message | string | Detail message of the error |
| code | enum | Error code enum for API Error. |
| meta_code | number | API response meta code. |
| status_code | number | HTTP status code. |
| response_body | string | API response body. |
| response_header | object | API response header. |
|
The AfterShip SDK has the following resource which are exactly the same as the API endpoints:
- trackingResource
- Get trackings
- Create a tracking
- Get a tracking by ID
- Update a tracking by ID
- Delete a tracking by ID
- Retrack an expired tracking by ID
- Mark tracking as completed by ID
- courierResource
- Get couriers
- Detect courier
- courierConnectionResource
- Get courier connections
- Create courier connections
- Get courier connection by id
- Update courier connection by id
- Delete courier connection by id
- estimatedDeliveryDateResource
- Prediction for the Estimated Delivery Date
- Batch prediction for the Estimated Delivery Date
GET /trackings
response = AftershipAPI::Tracking.get_trackings()
p responsePOST /trackings
request = AftershipAPI::Model::CreateTrackingRequest.new
request.tracking_number = "valid_value"
response = AftershipAPI::Tracking.create_tracking(body: request)
p responseGET /trackings/{id}
response = AftershipAPI::Tracking.get_tracking_by_id(id:"valid_value", )
p responsePUT /trackings/{id}
request = AftershipAPI::Model::UpdateTrackingByIdRequest.new
response = AftershipAPI::Tracking.update_tracking_by_id(id:"valid_value", body: request)
p responseDELETE /trackings/{id}
response = AftershipAPI::Tracking.delete_tracking_by_id(id:"valid_value", )
p responsePOST /trackings/{id}/retrack
response = AftershipAPI::Tracking.retrack_tracking_by_id(id:"valid_value", )
p responsePOST /trackings/{id}/mark-as-completed
request = AftershipAPI::Model::MarkTrackingCompletedByIdRequest.new
response = AftershipAPI::Tracking.mark_tracking_completed_by_id(id:"valid_value", body: request)
p responseGET /couriers
response = AftershipAPI::Courier.get_couriers()
p responsePOST /couriers/detect
request = AftershipAPI::Model::DetectCourierRequest.new
request.tracking_number = "valid_value"
response = AftershipAPI::Courier.detect_courier(body: request)
p responseGET /courier-connections
response = AftershipAPI::CourierConnection.get_courier_connections()
p responsePOST /courier-connections
request = AftershipAPI::Model::PostCourierConnectionsRequest.new
request.courier_slug = "valid_value"
request.credentials =
response = AftershipAPI::CourierConnection.post_courier_connections(body: request)
p responseGET /courier-connections/{id}
response = AftershipAPI::CourierConnection.get_courier_connections_by_id(id:"valid_value", )
p responsePATCH /courier-connections/{id}
request = AftershipAPI::Model::PutCourierConnectionsByIdRequest.new
request.credentials =
response = AftershipAPI::CourierConnection.put_courier_connections_by_id(id:"valid_value", body: request)
p responseDELETE /courier-connections/{id}
response = AftershipAPI::CourierConnection.delete_courier_connections_by_id(id:"valid_value", )
p responsePOST /estimated-delivery-date/predict
request = AftershipAPI::Model::EstimatedDeliveryDateRequest.new
request.slug = "valid_value"
origin_address = AftershipAPI::Model::EstimatedDeliveryDateRequestOriginAddress.new
request.origin_address = origin_address
destination_address = AftershipAPI::Model::EstimatedDeliveryDateRequestDestinationAddress.new
request.destination_address = destination_address
response = AftershipAPI::EstimatedDeliveryDate.predict(body: request)
p responsePOST /estimated-delivery-date/predict-batch
request = AftershipAPI::Model::PredictBatchRequest.new
response = AftershipAPI::EstimatedDeliveryDate.predict_batch(body: request)
p responseIf you get stuck, we're here to help:
- Issue Tracker for questions, feature requests, bug reports and general discussion related to this package. Try searching before you create a new issue.
- Contact AfterShip official support via support@aftership.com
Copyright (c) 2025 AfterShip
Licensed under the MIT license.
