Track()

This method is used to track a previously created label.

Syntax

module.exports = async function Track(request) {
// Your code here
}
import { TrackingRequest, TrackingResponse } from "@shipengine/connect-carrier-api";
export default async function Track(
request: TrackingRequest
): Promise<TrackingResponse> {
// Your code here
}

Parameters

TrackingRequest

An object containing information about the label to track.

NameTypeNullable?Description
authorization

authorization object

The authorization information necessary to fulfill this request.

metadata

metadata object

This object should contain all of the necessary properties needed to make authenticated requests with the carrier when an AuthProcess has not been configured. Every property included here will be persisted by ShipEngine Connect and included on each subsequent request from this user.

identifiers

identifier object[]

Array of identifiers describing the label to be tracked.

attributesobject[]

Extra attributes of a shipment needed in tracking.

attributes[].typestring

The attribute type.

attributes[].valuestring

The value associated with that key.

Return Value

TrackingResponse

This object model represents the response from a successful tracking request.

NameTypeRequired?Description
metadata

metadata object

This object should contain all of the necessary properties needed to make authenticated requests with the carrier. Every property included here will be persisted by ShipEngine Connect and included on each subsequent request from this user.

tracking_infoobject

This model represents tracking information for a shipment.

tracking_info   .carrier_namestring

The human readable name of the carrier tracking this shipment.

tracking_info   .tracking_numberstring

The carrier specific tracking identifier for this shipment.

tracking_info   .standardized_status_codestring

This represents the ShipEngine supported status codes for a shipment.

Valid values include the following:

  • UN - Unknown
  • AC - Accepted
  • IT - In Transit
  • DE - Delivered
  • EX - Exception
  • AT - Delivery Attempt
  • NY - Not Yet in system
tracking_info   .carrier_status_codestring

The carrier specific status code of this shipment's tracking status.

tracking_info   .carrier_status_descriptionstring

The human readable description of this shipment's tracking status.

tracking_info   .shipped_datetimestring

When the package(s) in this shipment were turned over to the carrier. Formatted per https://tools.ietf.org/html/rfc3339. Must be in UTC.

tracking_info   .estimated_delivery_datetimestring

When the package(s) in this shipment are expected to arrive at their destination. Formatted per https://tools.ietf.org/html/rfc3339. Must be in UTC.

tracking_info   .actual_delivery_datetimestring

When the package(s) in this shipment arrived at their destination. Formatted per https://tools.ietf.org/html/rfc3339. Must be in UTC.

tracking_info   .shipping_problem_descriptionstring

A human readable description of why the shipment is in an error state.

tracking_info.weightnumber

The weight measured by the carrier of the package(s) in this shipment.

tracking_info.dimensions

demension object

The dimensions measured by the carrier of the package(s).

tracking_info.serviceobject

A shipping provider specific service.

tracking_info   .service   .codestring

The code specific to a shipping provider service.

tracking_info   .service   .namestring

The name of this shipping provider service.

tracking_info.packagingstring

The carrier observed type of packages in this shipment.

tracking_info   .package_countnumber

The carrier observed count of packages in this shipment.

tracking_info.events

track events object[]

The carrier observed type of packages in this shipment.

tracking_info   .shipping_problemboolean

Whether or not this shipment has entered an error state.

tracking_info   .shipping_problem_codestring

The unique identifying code for the type of error encountered by this shipment.

tracking_info   .error_descriptionstring

The human readable explanation of the error encountered by this shipment.

Example

module.exports = async function Track(request) {
// STEP 1: Validation
// STEP 2: Create the data that the carrier's API expects
let data = {
operation: "track",
session_id: request.metadata.id,
tracking_number: request.identifiers.filter((identifier) => identifier.type === 'tracking_number').value,
};
// STEP 3: Call the carrier's API
const response = await apiClient.request({ data });
// STEP 4: Create the output data that ShipEngine expects
return formatTrack(response.data);
}
import {
TrackingRequest,
TrackingResponse
} from "@shipengine/connect-carrier-api";
export default async function Track(request: TrackingRequest): Promise<TrackingResponse> {
// STEP 1: Validation
// STEP 2: Create the data that the carrier's API expects
let data = {
operation: "track",
session_id: request.metadata.id,
tracking_number: request.identifiers.filter((identifier) => identifier.type === 'tracking_number').value,
};
// STEP 3: Call the carrier's API
const response = await apiClient.request<TrackAPIResponse>({ data });
// STEP 4: Create the output data that ShipEngine expects
return formatTrack(response.data);
}