Use .Net to track CTT shipments with CTT Tracking API.
- Real-time CTT tracking.
- Batch CTT tracking.
- Other features to manage your CTT tracking.
Downloading the NuGet package using the dotnet CLI
$ dotnet add package trackingmore
Downloading NuGet Packages with the NuGet Command Line Tool
$ nuget install trackingmore
The difference with dotnet cli is that you need to manually modify the .csproj file and add the following code
<ItemGroup>
<PackageReference Include="TrackingMore" Version="0.1.1" />
</ItemGroup>
Get the API key:
To use this API, you need to generate your API key.
- Click here to access TrackingMore admin.
-
Go to the "Developer" section.
-
Click "Generate API Key".
-
Give a name to your API key, and click "Save" .
Then, start to track your CTT shipments.
Create a tracking (Real-time tracking):
using TrackingMoreAPI;
using TrackingMoreAPI.Model.Trackings;
namespace Testing;
public class Test
{
static void Main(string[] args)
{
try
{
string apiKey = "your api key";
TrackingMore trackingMore = new TrackingMore(apiKey);
CreateTrackingParams createTrackingParams = new CreateTrackingParams();
createTrackingParams.trackingNumber = "0301006785462006320995";
createTrackingParams.courierCode = "ctt";
var apiResponse = trackingMore.Tracking.CreateTracking(createTrackingParams);
Console.WriteLine(apiResponse.meta.code);
Console.WriteLine(apiResponse.data.trackingNumber);
Console.WriteLine(apiResponse.data.courierCode);
}
catch (TrackingMoreException ex)
{
Console.WriteLine("Catch custom exceptions:" + ex.Message);
}
catch (TimeoutException ex)
{
Console.WriteLine("Timeout Exception: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Catch other exceptions:" + ex.Message);
}
}
}
Create trackings (Max. 40 tracking numbers create in one call):
using TrackingMoreAPI;
using TrackingMoreAPI.Model.Trackings;
namespace Testing;
public class Test
{
static void Main(string[] args)
{
try
{
List<CreateTrackingParams> trackingParamsList = new List<CreateTrackingParams>();
CreateTrackingParams trackingParams1 = new CreateTrackingParams
{
trackingNumber = "LK201223662AU",
courierCode = "ctt"
};
trackingParamsList.Add(trackingParams1);
CreateTrackingParams trackingParams2 = new CreateTrackingParams
{
trackingNumber = "LH290032509AU",
courierCode = "ctt"
};
trackingParamsList.Add(trackingParams2);
var apiResponse = trackingMore.Tracking.BatchCreateTrackings(trackingParamsList);
Console.WriteLine(apiResponse.meta.code);
foreach (var item in apiResponse.data.success)
{
Console.WriteLine("trackingNumber: " + item.trackingNumber);
Console.WriteLine("courierCode: " + item.courierCode);
Console.WriteLine();
}
foreach (var item in apiResponse.data.error)
{
Console.WriteLine("trackingNumber: " + item.trackingNumber);
Console.WriteLine("courierCode: " + item.courierCode);
Console.WriteLine();
}
}
catch (TrackingMoreException ex)
{
Console.WriteLine("Catch custom exceptions:" + ex.Message);
}
catch (TimeoutException ex)
{
Console.WriteLine("Timeout Exception: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Catch other exceptions:" + ex.Message);
}
}
}
Get status of the shipment:
using TrackingMoreAPI;
using TrackingMoreAPI.Model.Trackings;
namespace Testing;
public class Test
{
static void Main(string[] args)
{
try
{
GetTrackingResultsParams getTrackingResultsParams = new GetTrackingResultsParams();
# Perform queries based on various conditions
# getTrackingResultsParams.trackingNumbers = "LH290032509AU,LK201223662AU";
getTrackingResultsParams.courierCode = "ctt";
getTrackingResultsParams.createdDateMin = "2023-08-23T06:00:00+00:00";
getTrackingResultsParams.createdDateMax = "2023-09-05T07:20:42+00:00";
var apiResponse = trackingMore.Tracking.GetTrackingResults(getTrackingResultsParams);
Console.WriteLine(apiResponse.meta.code);
foreach (var item in apiResponse.data)
{
Console.WriteLine("trackingNumber: " + item.trackingNumber);
Console.WriteLine("courierCode: " + item.courierCode);
Console.WriteLine();
}
}
catch (TrackingMoreException ex)
{
Console.WriteLine("Catch custom exceptions:" + ex.Message);
}
catch (TimeoutException ex)
{
Console.WriteLine("Timeout Exception: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Catch other exceptions:" + ex.Message);
}
}
}
Update a tracking by ID:
using TrackingMoreAPI;
using TrackingMoreAPI.Model.Trackings;
namespace Testing;
public class Test
{
static void Main(string[] args)
{
try
{
UpdateTrackingParams updateTrackingParams = new UpdateTrackingParams();
updateTrackingParams.customerName = "New name";
updateTrackingParams.note = "New tests order note";
string idString = "9a1339cb81ec08b52985867d176a0ba4";
var apiResponse = trackingMore.Tracking.UpdateTrackingByID(idString, updateTrackingParams);
Console.WriteLine(apiResponse.meta.code);
if(apiResponse.data != null){
Console.WriteLine(apiResponse.data.trackingNumber);
Console.WriteLine(apiResponse.data.courierCode);
Console.WriteLine(apiResponse.data.customerName);
Console.WriteLine(apiResponse.data.note);
}
}
catch (TrackingMoreException ex)
{
Console.WriteLine("Catch custom exceptions:" + ex.Message);
}
catch (TimeoutException ex)
{
Console.WriteLine("Timeout Exception: " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Catch other exceptions:" + ex.Message);
}
}
}