Shipment Tracking API

The WooCommerce REST API enable external apps use a set of API endpoints to read and write various parts of WooCommerce data. The AST plugin extends the WooCommerce Rest API and adds Shipment Tracking endpoints that allows to create, view, and delete shipment tracking information in orders.

To use the Shipment Tracking endpoint, you’ll need to generate a Rest API Key for your WooCommerce store. These API keys are the permission for external systems to connect with your store’s API.

How To Get WooCommerce API Keys

To generate API keys for your WooCommerce store, navigate to WooCommerce > Settings > Advanced > Rest API and Select Add Key. You are taken to the Key Details screen:

blank
  1. Add a Description.
  2. Select the User you would like to generate a key for in the dropdown (admin user)
  3. Select a level of access for this API key – Read/Write access.
  4. Select Generate API Key, and WooCommerce will create API keys for that user.

Shipment Tracking Endpoint

The Shipment Tracking endpoint supports the following methods:

  • Add tracking information and fulfill orders
  • Retrieve tracking information from orders
  • Delete tracking information from orders
  • Get the shipping provider’s list

Endpoint URL:

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

Please note: the shipment tracking endpoint works with WooCommerce API v1, v2, and v3. In the documentation, only v1 is shown. We are also compatible with old version od the AST PRO REST API endpoint – wc-ast/v3.

Shipment Tracking 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

Add Shipment tracking

This endpoint allows to add new tracking info to orders:w 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-tracking
	-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"

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 a response with an 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 the 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

Then 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

Free

Download