Shipment Tracking API

The WooCommerce REST API provides a set of API endpoints for external applications to access and manage various parts of WooCommerce data. AST PRO expands upon the WooCommerce REST API by adding shipment tracking endpoints, allowing you to create, view, retrieve, and delete individual shipment tracking information for orders.

To utilize the shipment tracking endpoint, you must first generate a REST API key in your WooCommerce store. This key acts as an authorization for external systems to connect with your store’s API.

How To Get WooCommerce API Keys

To create API keys for your WooCommerce store, follow these steps:

blank
  1. Go to WooCommerce > Settings > Advanced > Rest API.
  2. Click on “Add Key”.
  3. On the Key Details screen, provide a Description for the API key.
  4. Choose the User you want to generate the key for in the dropdown (e.g. admin user).
  5. Set the level of access for the API key, such as Read/Write.
  6. Click on “Generate API Key” and WooCommerce will create the API keys for the selected user.

Shipment Tracking API Endpoint

The Shipment Tracking API endpoint provides support for the following methods:

  1. Adding Tracking Information and Order Fulfillment: This method allows you to add tracking information to your orders and fulfill them.
  2. Adding Item-Level Tracking Information and Order Fulfillment: This method allows you to add tracking information to specific items within an order and fulfill the order accordingly.
  3. Retrieving Tracking Information from Orders: This method enables you to retrieve tracking information for orders that have been fulfilled.
  4. Deleting Tracking Information from Orders: This method allows you to remove tracking information from orders if necessary.
  5. List of Shipping Providers: This method provides you with a list of available shipping providers to choose from.

Endpoint URL:

https://yourdomaon.com/wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings

Please note: Our shipment tracking endpoint is compatible with multiple versions of the WooCommerce API, including v1, v2, and v3. Although the documentation only showcases its usage with v1, it is also compatible with the older version of the AST PRO REST API endpoint (wc-ast-pro/v3).

Shipment Tracking API Properties

These are the available meta field that can be used when updating the Shipment Tracking API:

ATTRIBUTETYPEDESCRIPTIONPERMISSIONS
order_idStringUnique identifier for orderread-only
tracking_numberStringTracking numberRequired
tracking_providerStringTracking provider nameRequired
date_shippedDateDate when the package was shipped – default to the date/time that the tracking was added via the APIOptional
replace_trackingBoolean0 – add the tracking info in addition to tracking info that was already added to the order. 1 – replace the current tracking numbers for the orders (Defaults to 0)Optional
status_shippedInteger0 – do not change the order status, 1 – change order status to “Shipped” (completed), 2 – change the order status to custom status “Partially Shipped” (Defaults to 0).Optional
skuStringLine item SKU – Add tracking per itemOptional
qtyIntegerLine item quantity – Add tracking per itemOptional

Add Shipment tracking

This endpoint allows to add new tracking info to orders:

POST /wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/

curl -X POST https://your-domain.com/wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings
	-u consumer_key:consumer_secret 
	-H "Content-Type: application/json" 
	-d '{
		"tracking_provider": "Fedex",
		"tracking_number": "12345678",
		"date_shipped": "2019-03-08",
		"status_shipped": 1,
		"replace_tracking": 1
	}'
//response example:
"Tracking ID: fb7170d97d0e628bc3b565999d07c6a9"

Add Shipment Tracking Per Item

Tracking per item with the API
If you use the Tracking Per Item Add-on, you can add tracking to the API endpoint to specific line items (products) using the product SKU and the quantity shipped properties.

For example, if you received an order of 5 items and want to send them in s packages with different tracking numbers:

Package 1 – tracking number – 123456
Products:

  • t-shirt x 1
  • blue-jeans x 1

Package 2 – tracking number – 456789

  • t-shirt x 1
  • blue-jeans x 2

Add tracking for Package One:

POST /wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/
curl -X POST https://your-domain.com/wp-json/wc-ast-pro/v3/orders/<order_id>/shipment-trackings 
	-u consumer_key:consumer_secret 
	-H "Content-Type: application/json" 
	-d '{
		"tracking_provider": "USPS",
		"tracking_number": "123456",
		"date_shipped": "2020-01-24",
		"status_shipped": 2,
    		"sku": t-shirt,blue-jeans,
  		"qty": 1,1 
	}'

Add tracking for Package Two:

curl -X POST https://your-domain.com/wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings 
	-u consumer_key:consumer_secret 
	-H "Content-Type: application/json" 
	-d '{
		"tracking_provider": "USPS",
		"tracking_number": "456879",
		"date_shipped": "2020-01-24",
		"status_shipped": 1,
    		"sku": t-shirt,blue-jeans, 
  		"qty": 1,2 
	}'

Get shipment tracking

With this endpoint, you can list all tracking info added to an order. You will need to pass the order id and you’ll get response with array of tracking numbers added to that order,

GET /wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/

curl -X GET https://your-domain.com/wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings 
  -u consumer_key:consumer_secret 
  
  //JSON response:
  
  {
  "tracking_id": "feb9bde4475fda92cc9408607b7ecb66",
  "tracking_provider": "Fedex",
  "tracking_link": "http://www.fedex.com/Tracking?action=track&tracknumbers=12345678",
  "tracking_number": "12345678",
  "date_shipped": "2019-03-08",
  "_links": {
    "self": [
      {
        "href": "https://your-domain.com/wp-json/wc/v1/orders/340/shipment-trackings"
      }
    ],
    "collection": [
      {
        "href": "https://your-domain.com/wp-json/wc/v1/orders/340/shipment-trackings"
      }
    ],
    "up": [
      {
        "href": "https://your-domain.com/wp-json/wc/v1/orders/340"
      }
    ]
  }
}

Delete Shipment Tracking

You can delete tracking numbers from orders, you will need to pass the order id and the tracking_id for this tracking number:

DELETE /wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/

curl -X DELETE https://your-domain.com/wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/fa61d174a05d2f34323b51d92823947d 
  -u consumer_key:consumer_secret 
  
//response example:
"Tracking ID: fa61d174a05d2f34323b51d92823947d"

Get Shipping Providers

You can get all the active shipping providers for the order

GET /wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/providers

curl -X GET https://your-domain.com/wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/providers
    -u consumer_key:consumer_secret

JSON response example:

{
    "Austria": {
        "DPD Austria": "https://tracking.dpd.de/parcelstatus?locale=de_AT&query=%number%",
        "post.at": "http://www.post.at/sendungsverfolgung.php?pnum1=%number%"
    },
    "Australia": {
        "Australia Post": "http://auspost.com.au/track/track.html?id=%number%",
        "CouriersPlease": "https://www.couriersplease.com.au/tools-track/no/%number%"
    },
    "Canada": {
        "Canada Post": "https://www.canadapost.ca/track-reperage/en#/search?searchFor=%number%",
        "Canpar": "https://www.canpar.ca/en/track/tracking.jsp"
    },
    "Chile": {
        "Correos Chile": "https://www.correos.cl/web/guest/seguimiento-en-linea?codigos=%number%"
    },
    "China": {
        "China Post": "http://english.chinapost.com.cn/html1/folder/1408/3929-1.htm?content=%number%",
        "EMS": "https://www.ems.post/en/global-network/tracking"
    },
    "France": {
        "Chronopost": "https://www.chronopost.fr/fr/chrono_suivi_search?listeNumerosLT=%number%",
        "Colis Privé": "https://www.colisprive.com/moncolis/pages/detailColis.aspx?numColis=%number%"
    },
    "India": {
        "Delhivery": "https://www.delhivery.com/track/package/%number%"
    },
    "United States (US)": {
        "DHL US": "https://www.logistics.dhl/us-en/home/tracking/tracking-ecommerce.html?tracking-id=%number%",
        "Associated Global Systems": "https://tracking.agsystems.com/",
        "DHL Parcel": "https://www.logistics.dhl/us-en/home/tracking/tracking-ecommerce.html?tracking-id=%number%",
        "TNT": "https://www.tnt.com/express/en_us/site/tracking.html?searchType=con&cons=%number%",
        "Speedex Courier": "http://www.speedexcourier.com/",
        "UPS": "http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=%number%",
        "USPS": "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=%number%"
    }
}

API Request Errors

In the events of API request errors, AST uses conventional HTTP response codes in the 4XX and 5XX range to indicate the reason behind the error.

Error CodeError typeSample Error Message
400BadRequestMissing parameter(s): tracking_number
400BadRequestMissing parameter(s): tracking_provider
404Not FoundInvalid order ID
404Not FoundRequests to resources that don’t exist or are missing
401UnauthorizedAuthentication or permission error, e.g. incorrect API keys
500Internal Server ErrorServer error

Postman example 

Please check screenshot for setup in postman.

Create new request and set method Post. Insert URL and in the Body section insert all the tracking information.

blank

Than go to the Authorization section and select Type Basic Auth. Use REST API Consumer key and consumer secret in the username and password field and click on Send.

blank

$129.00

Billed annually

Buy Now