AfterShipTracking 7.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AfterShipTracking --version 7.0.1                
NuGet\Install-Package AfterShipTracking -Version 7.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AfterShipTracking" Version="7.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AfterShipTracking --version 7.0.1                
#r "nuget: AfterShipTracking, 7.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AfterShipTracking as a Cake Addin
#addin nuget:?package=AfterShipTracking&version=7.0.1

// Install AfterShipTracking as a Cake Tool
#tool nuget:?package=AfterShipTracking&version=7.0.1                

AfterShip Tracking API library for C#

This library allows you to quickly and easily use the AfterShip Tracking API via C#.

For updates to this library, see our GitHub release page.

If you need support using AfterShip products, please contact support@aftership.com.

Table of Contents

Before you begin

Before you begin to integrate:

Quick Start

Installation

Using the [.NET Core command-line interface (CLI) tools]:

dotnet add package AfterShipTracking

Using the [NuGet Command Line Interface (CLI)]:

nuget install AfterShipTracking

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "AfterShipTracking".
  5. Click on the AfterShipTracking package, select the appropriate version in the right-tab and click Install.

For with Visual Studio Code:

  1. Open the Command Palette then type "NuGet Package Manager"
  2. In the opened window, search for "AfterShipTracking".
  3. Select the AfterShipTracking package and the package version.

Constructor

Create AfterShip instance with options

Name Type Required Description
api_key string Your AfterShip API key
auth_type enum Default value: AfterShipConfiguration.AUTHENTICATION_TYPE_API_KEY <br > AES authentication: AfterShipConfiguration.AUTHENTICATION_TYPE_AES <br > RSA authentication: AfterShipConfiguration.AUTHENTICATION_TYPE_RSA
api_secret string Required if the authentication type is AfterShipConfiguration.AUTHENTICATION_TYPE_AES or AfterShipConfiguration.AUTHENTICATION_TYPE_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. <br > Default value: null <br > 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.

Example

using AfterShipTracking;

class Program
{
    static void Main()
    {
        try
        {
            AfterShipClient client = new AfterShipClient(
                            apiKey: "YOUR_API_KEY",
                            apiSecret: "YOUR_AES_SECRET",
                            authenticationType: AfterShipConfiguration.AUTHENTICATION_TYPE_AES);

            CreateTrackingOptions options = new CreateTrackingOptions();
            options.CreateTrackingRequest = new CreateTrackingRequest();
            TrackingCreateTrackingRequest newTracking = new TrackingCreateTrackingRequest();
            newTracking.TrackingNumber = "<tracking_number>";
            newTracking.Slug = "<slug>";
            options.CreateTrackingRequest.Tracking = newTracking;
            Tracking tracking = client.Tracking.CreateTracking(options);
            if (tracking != null)
            {
                Console.WriteLine(tracking.Id);
            }
        }catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
}

Rate Limiter

See the Rate Limit to understand the AfterShip rate limit policy.

Error Handling

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.

Error List

code meta_code status_code message
INVALID_REQUEST 400 400 The request was invalid or cannot be otherwise served.
INVALID_JSON 4001 400 Invalid JSON data.
TRACKING_ALREADY_EXIST 4003 400 Tracking already exists.
TRACKING_DOES_NOT_EXIST 4004 404 Tracking does not exist.
TRACKING_NUMBER_INVALID 4005 400 The value of tracking_number is invalid.
TRACKING_REQUIRED 4006 400 tracking object is required.
TRACKING_NUMBER_REQUIRED 4007 400 tracking_number is required.
VALUE_INVALID 4008 400 The value of [field_name] is invalid.
VALUE_REQUIRED 4009 400 [field_name] is required.
SLUG_INVALID 4010 400 The value of slug is invalid.
MISSING_OR_INVALID_REQUIRED_FIELD 4011 400 Missing or invalid value of the required fields for this courier. Besides tracking_number, also required: [field_name]
BAD_COURIER 4012 400 The error message will be one of the following:<br/>1. Unable to import shipment as the carrier is not on your approved list for carrier auto-detection. Add the carrier here: https://admin.aftership.com/settings/couriers<br/>2. Unable to import shipment as we don’t recognize the carrier from this tracking number.<br/>3. Unable to import shipment as the tracking number has an invalid format.<br/>4. Unable to import shipment as this carrier is no longer supported.<br/>5. Unable to import shipment as the tracking number does not belong to a carrier in that group.
INACTIVE_RETRACK_NOT_ALLOWED 4013 400 Retrack is not allowed. You can only retrack an inactive tracking.
NOTIFICATION_REUQIRED 4014 400 notification object is required.
ID_INVALID 4015 400 The value of id is invalid.
RETRACK_ONCE_ALLOWED 4016 400 Retrack is not allowed. You can only retrack each shipment once.
TRACKING_NUMBER_FORMAT_INVALID 4017 400 The format of tracking_number is invalid.
API_KEY_INVALID 401 401 The API key is invalid.
REQUEST_NOT_ALLOWED 403 403 The request is understood, but it has been refused or access is not allowed.
NOT_FOUND 404 404 The URI requested is invalid or the resource requested does not exist.
TOO_MANY_REQUEST 429 429 You have exceeded the API call rate limit. The default limit is 10 requests per second.
INTERNAL_ERROR 500 502 503 504 500 502 503 504 Something went wrong on AfterShip's end.

Endpoints

The AfterShip instance has the following properties which are exactly the same as the API endpoints:

  • courier - Get a list of our supported couriers.
  • tracking - Create trackings, update trackings, and get tracking results.
  • last_checkpoint - Get tracking information of the last checkpoint of a tracking.
  • notification - Get, add or remove contacts (sms or email) to be notified when the status of a tracking has changed.
  • estimated-delivery-date - Get estimated delivery date for your order.

/trackings

POST /trackings

CreateTrackingOptions options = new CreateTrackingOptions();
options.CreateTrackingRequest = new CreateTrackingRequest();
TrackingCreateTrackingRequest newTracking = new TrackingCreateTrackingRequest();
newTracking.TrackingNumber = "<tracking_number>";
newTracking.Slug = "<slug>";
options.CreateTrackingRequest.Tracking = newTracking;
Tracking tracking = client.Tracking.CreateTracking(options);
if (tracking != null)
{
    Console.WriteLine(tracking.Id);
}

DELETE /trackings/:id

DeleteTrackingByIdOptions deleteOptions = new DeleteTrackingByIdOptions();
PartialDeleteTracking resp = client.Tracking.DeleteTrackingById("<tracking_id>");

if (resp != null)
{
    Console.WriteLine(resp.Id);
}

GET /trackings

GetTrackingsOptions options = new GetTrackingsOptions();
options.Keyword = "test";
GetTrackingsResponseTrackingListData trackingsData = client.Tracking.GetTrackings(options);
if (trackingsData != null && trackingsData.Trackings != null)
{
    for (int i = 0; i < trackingsData.Trackings.Length; i++)
    {
        Console.WriteLine(trackingsData.Trackings[i].TrackingNumber);
    }
}

GET /trackings/:id

Tracking tracking = client.Tracking.GetTrackingById("<tracking_id>");
if (tracking != null)
{
   Console.WriteLine(tracking.TrackingNumber);
}

PUT /trackings/:id

UpdateTrackingByIdOptions updateOptions = new UpdateTrackingByIdOptions();
updateOptions.UpdateTrackingByIdRequest = new UpdateTrackingByIdRequest();
TrackingUpdateTrackingByIdRequest trackingToUpdate = new TrackingUpdateTrackingByIdRequest();
trackingToUpdate.Title = "this is a test new title";
trackingToUpdate.Note = "some note";
updateOptions.UpdateTrackingByIdRequest.Tracking = trackingToUpdate;
Tracking tracking = client.Tracking.UpdateTrackingById("<tracking_id>", updateOptions);

if (tracking != null)
{
    Console.WriteLine(tracking.Title);
    Console.WriteLine(tracking.Note);
}

POST /trackings/:id/retrack

RetrackTrackingByIdOptions options = new RetrackTrackingByIdOptions();
PartialUpdateTracking tracking = client.Tracking.RetrackTrackingById("<tracking_id>");
Console.WriteLine(tracking.TrackingNumber);

POST /trackings/:id/mark-as-completed

MarkTrackingCompletedByIdOptions options = new MarkTrackingCompletedByIdOptions();
PartialUpdateTracking tracking = client.Tracking.RetrackTrackingById("<tracking_id>");
Console.WriteLine(tracking.TrackingNumber);

/couriers

GET /couriers

GetUserCouriersOptions options = new GetUserCouriersOptions();
GetUserCouriersResponse resp = client.Courier.GetUserCouriers(options);
Console.WriteLine(resp.Total);

GET /couriers/all

GetAllCouriersOptions options = new GetAllCouriersOptions();
GetAllCouriersResponse resp = client.Courier.GetAllCouriers(options);
Console.WriteLine(resp.Total);

POST /couriers/detect

DetectCourierOptions options = new DetectCourierOptions();
DetectCourierRequest detectCourierRequest = new DetectCourierRequest();
TrackingDetectCourierRequest tracking = new TrackingDetectCourierRequest();
tracking.TrackingNumber = "<tracking_number>";
detectCourierRequest.Tracking = tracking;
options.DetectCourierRequest = detectCourierRequest;
DetectCourierResponse resp = client.Courier.DetectCourier(options);
Console.WriteLine(resp.Total);

/last_checkpoint

GET /last_checkpoint/:id

GetCheckpointByTrackingIdResponse resp = client.LastCheckpoint.GetCheckpointByTrackingId("<tracking_id>");
Console.WriteLine(resp.Slug);

/notifications

GET /notifications/:id

Notification notification =  client.Notification.GetNotificationByTrackingId("<tracking_id>");
Console.WriteLine(notification.Emails[0]);

POST /notifications/:id/add

AddNotificationByTrackingIdOptions options = new AddNotificationByTrackingIdOptions();
AddNotificationByTrackingIdRequest request = new AddNotificationByTrackingIdRequest();
NotificationRequestV1 notification = new NotificationRequestV1();
notification.Emails = new string?[] { "<your_email>" };
request.Notification = notification;
options.AddNotificationByTrackingIdRequest = request;

Notification result = client.Notification.AddNotificationByTrackingId("<tracking_id>", options);
Console.WriteLine(result.Emails[0]);

POST /notifications/:id/remove

DeleteNotificationByTrackingIdOptions options = new DeleteNotificationByTrackingIdOptions();
DeleteNotificationByTrackingIdRequest request = new DeleteNotificationByTrackingIdRequest();
NotificationRequestV1 notification = new NotificationRequestV1();
notification.Emails = new string?[] { "<your_email>" };
request.Notification = notification;
options.DeleteNotificationByTrackingIdRequest = request;

Notification result = client.Notification.DeleteNotificationByTrackingId("<tracking_id>", options);
Console.WriteLine(result.Emails[0]);

/estimated-delivery-date

POST /estimated-delivery-date/predict-batch

PredictBatchOptions options = new PredictBatchOptions();
PredictBatchRequest request = new PredictBatchRequest();

EstimatedDeliveryDateRequest estimatedDeliveryDateRequest = new EstimatedDeliveryDateRequest();

DestinationAddressEstimatedDeliveryDateRequest dest = new DestinationAddressEstimatedDeliveryDateRequest();
dest.Country = "<ISO 3166-1 country/region code>";
dest.State = "<ISO 3166-1 country/region code>";
estimatedDeliveryDateRequest.DestinationAddress = dest;

OriginAddressEstimatedDeliveryDateRequest origin = new OriginAddressEstimatedDeliveryDateRequest();
origin.Country = "<ISO 3166-1 country/region code>";
origin.State = "<ISO 3166-1 country/region code>";
estimatedDeliveryDateRequest.OriginAddress = origin;

estimatedDeliveryDateRequest.Slug = "<slug>";
estimatedDeliveryDateRequest.PickupTime = "2024-08-01 06:42:30";
request.EstimatedDeliveryDates = new EstimatedDeliveryDateRequest[] { estimatedDeliveryDateRequest };

options.PredictBatchRequest = request;

EstimatedPickupEstimatedDeliveryDateRequest r2 = new EstimatedPickupEstimatedDeliveryDateRequest();
r2.BusinessDays = new int?[] { 0 };

PredictBatchResponse resp = client.EstimatedDeliveryDate.PredictBatch(options);
Console.WriteLine(resp.EstimatedDeliveryDates[0].PickupTime);

Help

If 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

License

Copyright (c) 2024 AfterShip

Licensed under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0 89 10/25/2024
8.0.0 150 8/22/2024
7.0.1 124 8/19/2024