Skip to content

Instantly share code, notes, and snippets.

@gedex
Last active March 21, 2020 09:05
Show Gist options
  • Save gedex/cf3639918fdec31feceffd03eff7f3d4 to your computer and use it in GitHub Desktop.
Save gedex/cf3639918fdec31feceffd03eff7f3d4 to your computer and use it in GitHub Desktop.
WooCommerce Shipment Tracking REST API introduced in 1.5.0

Shipment Tracking REST API

The shipment tracking REST API allows you to create, view, and delete individual shipment tracking. The endpoint is /wp-json/wc/v1/orders/shipment-trackings.

Shipment Tracking Properties

Attribute Type Description
tracking_id string Unique identifier for shipment tracking read-only
tracking_number string Tracking number required
tracking_provider string Tracking provider name
tracking_link url Tracking link
date_shipped date Date when package was shipped

Create a shipment tracking

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

If predefined provider name is used, then no need to pass tracking_link.

curl -X POST https://example.com/wp-json/wc/v1/orders/645/shipment-trackings \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "tracking_provider": "TNT Express (consignment)",
  "tracking_number": "12345678",
}'

JSON response example:

{
  "tracking_id": "7f4978c390ee633c6294ae0f258656f9",
  "tracking_provider": "TNT Express (consignment)",
  "tracking_link": "http://www.tnt.com/webtracker/tracking.do?requestType=GEN&searchType=CON&respLang=en&\nrespCountry=GENERIC&sourceID=1&sourceCountry=ww&cons=12345678&navigation=1&g\nenericSiteIdent=",
  "tracking_number": "12345678",
  "date_shipped": "2016-08-11",
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings/7f4978c390ee633c6294ae0f258656f9"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497"
      }
    ]
  }
}

Using custom provider:

curl -X POST https://example.com/wp-json/wc/v1/orders/645/shipment-trackings \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "custom_tracking_provider": "Custom",
  "custom_tracking_link": "https://example.com?q=%1$s",
  "tracking_number": "12345678"
}'

Retrieve a shipment tracking

GET /wp-json/wc/v1/orders/<order_id>/shipment-trackings/<tracking-id>
curl -X GET https://example.com/wp-json/wc/v1/orders/645/shipment-trackings/7f4978c390ee633c6294ae0f258656f9 \
    -u consumer_key:consumer_secret \

JSON response example:

{
  "tracking_id": "7f4978c390ee633c6294ae0f258656f9",
  "tracking_provider": "TNT Express (consignment)",
  "tracking_link": "http://www.tnt.com/webtracker/tracking.do?requestType=GEN&searchType=CON&respLang=en&\nrespCountry=GENERIC&sourceID=1&sourceCountry=ww&cons=12345678&navigation=1&g\nenericSiteIdent=",
  "tracking_number": "12345678",
  "date_shipped": "2016-08-11",
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings/7f4978c390ee633c6294ae0f258656f9"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497"
      }
    ]
  }
}

List all shipment trackings

GET /wp-json/wc/v1/orders/<order_id>/shipment-trackings/
curl -X GET https://example.com/wp-json/wc/v1/orders/645/shipment-trackings \
    -u consumer_key:consumer_secret \

JSON response example:

[
  {
    "tracking_id": "c8ce8278b1e6ddc93b1b465992bac886",
    "tracking_provider": "TNT Express (consignment)",
    "tracking_link": "http://www.tnt.com/webtracker/tracking.do?requestType=GEN&searchType=CON&respLang=en&\nrespCountry=GENERIC&sourceID=1&sourceCountry=ww&cons=12345678&navigation=1&g\nenericSiteIdent=",
    "tracking_number": "12345678",
    "date_shipped": "2016-08-10",
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings/c8ce8278b1e6ddc93b1b465992bac886"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings"
        }
      ],
      "up": [
        {
          "href": "https://example.com/wp-json/wc/v1/orders/4497"
        }
      ]
    }
  }
]

Delete a shipment tracking

DELETE /wp-json/wc/v1/orders/<order_id>/shipment-trackings/<tracking-id>
curl -X DELETE https://example.com/wp-json/wc/v1/orders/645/shipment-trackings/c8ce8278b1e6ddc93b1b465992bac886 \
    -u consumer_key:consumer_secret \

JSON response example:


  "tracking_id": "c8ce8278b1e6ddc93b1b465992bac886",
  "tracking_provider": "TNT Express (consignment)",
  "tracking_link": "http://www.tnt.com/webtracker/tracking.do?requestType=GEN&searchType=CON&respLang=en&\nrespCountry=GENERIC&sourceID=1&sourceCountry=ww&cons=12345678&navigation=1&g\nenericSiteIdent=",
  "tracking_number": "12345678",
  "date_shipped": "2016-08-10",
  "_links": {
    "self": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings/c8ce8278b1e6ddc93b1b465992bac886"
      }
    ],
    "collection": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497/shipment-trackings"
      }
    ],
    "up": [
      {
        "href": "https://example.com/wp-json/wc/v1/orders/4497"
      }
    ]
  }
}

List all shipment tracking providers

GET /wp-json/wc/v1/orders/<order_id>/shipment-trackings/providers
curl -X GET https://example.com/wp-json/wc/v1/orders/645/shipment-trackings/providers \
    -u consumer_key:consumer_secret \

JSON response example:

{
  "Australia": {
    "Australia Post": "http://auspost.com.au/track/track.html?id=%1$s",
    "Fastway Couriers": "http://www.fastway.com.au/courier-services/track-your-parcel?l=%1$s"
  },
  "Austria": {
    "post.at": "http://www.post.at/sendungsverfolgung.php?pnum1=%1$s",
    "dhl.at": "http://www.dhl.at/content/at/de/express/sendungsverfolgung.html?brand=DHL&AWB=%1$s",
    "DPD.at": "https://tracking.dpd.de/parcelstatus?locale=de_AT&query=%1$s"
  },
  "Brazil": {
    "Correios": "http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=%1$s"
  },
  "Canada": {
    "Canada Post": "http://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=%1$s"
  },
  "Czech Republic": {
    "PPL.cz": "http://www.ppl.cz/main2.aspx?cls=Package&idSearch=%1$s",
    "Česká pošta": "https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=%1$s",
    "DHL.cz": "http://www.dhl.cz/cs/express/sledovani_zasilek.html?AWB=%1$s",
    "DPD.cz": "https://tracking.dpd.de/parcelstatus?locale=cs_CZ&query=%1$s"
  },
  "Finland": {
    "Itella": "http://www.posti.fi/itemtracking/posti/search_by_shipment_id?lang=en&ShipmentId=%1$s"
  },
  "France": {
    "Colissimo": "http://www.colissimo.fr/portail_colissimo/suivre.do?language=fr_FR&colispart=%1$s"
  },
  "Germany": {
    "DHL Intraship (DE)": "http://nolp.dhl.de/nextt-online-public/set_identcodes.do?lang=de&idc=%1$s&rfn=&extendedSearch=true",
    "Hermes": "https://tracking.hermesworld.com/?TrackID=%1$s",
    "Deutsche Post DHL": "http://nolp.dhl.de/nextt-online-public/set_identcodes.do?lang=de&idc=%1$s",
    "UPS Germany": "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=de_DE&InquiryNumber1=%1$s",
    "DPD.de": "https://tracking.dpd.de/parcelstatus?query=%1$s&locale=en_DE"
  },
  "Ireland": {
    "DPD.ie": "http://www2.dpd.ie/Services/QuickTrack/tabid/222/ConsignmentID/%1$s/Default.aspx",
    "An Post": "https://track.anpost.ie/TrackingResults.aspx?rtt=1&items=%1$s"
  },
  "Italy": {
    "BRT (Bartolini)": "http://as777.brt.it/vas/sped_det_show.hsm?referer=sped_numspe_par.htm&Nspediz=%1$s",
    "DHL Express": "http://www.dhl.it/it/express/ricerca.html?AWB=%1$s&brand=DHL"
  },
  "India": {
    "DTDC": "http://www.dtdc.in/dtdcTrack/Tracking/consignInfo.asp?strCnno=%1$s"
  },
  "Netherlands": {
    "PostNL": "https://mijnpakket.postnl.nl/Claim?Barcode=%1$s&Postalcode=%2$s&Foreign=False&ShowAnonymousLayover=False&CustomerServiceClaim=False",
    "DPD.NL": "http://track.dpdnl.nl/?parcelnumber=%1$s"
  },
  "New Zealand": {
    "Courier Post": "http://trackandtrace.courierpost.co.nz/Search/%1$s",
    "NZ Post": "http://www.nzpost.co.nz/tools/tracking?trackid=%1$s",
    "Fastways": "http://www.fastway.co.nz/courier-services/track-your-parcel?l=%1$s",
    "PBT Couriers": "http://www.pbt.com/nick/results.cfm?ticketNo=%1$s"
  },
  "South African": {
    "SAPO": "http://sms.postoffice.co.za/TrackingParcels/Parcel.aspx?id=%1$s"
  },
  "Sweden": {
    "Posten AB": "http://www.posten.se/sv/Kundservice/Sidor/Sok-brev-paket.aspx?search=%1$s",
    "DHL.se": "http://www.dhl.se/content/se/sv/express/godssoekning.shtml?brand=DHL&AWB=%1$s",
    "Bring.se": "http://tracking.bring.se/tracking.html?q=%1$s",
    "UPS.se": "http://wwwapps.ups.com/WebTracking/track?track=yes&loc=sv_SE&trackNums=%1$s",
    "DB Schenker": "http://privpakportal.schenker.nu/TrackAndTrace/packagesearch.aspx?packageId=%1$s"
  },
  "United Kingdom": {
    "DHL": "http://www.dhl.com/content/g0/en/express/tracking.shtml?brand=DHL&AWB=%1$s",
    "DPD.co.uk": "http://www.dpd.co.uk/tracking/trackingSearch.do?search.searchType=0&search.parcelNumber=%1$s",
    "InterLink": "http://www.interlinkexpress.com/apps/tracking/?reference=%1$s&postcode=%2$s#results",
    "ParcelForce": "http://www.parcelforce.com/portal/pw/track?trackNumber=%1$s",
    "Royal Mail": "https://www.royalmail.com/track-your-item/?trackNumber=%1$s",
    "TNT Express (consignment)": "http://www.tnt.com/webtracker/tracking.do?requestType=GEN&searchType=CON&respLang=en&\nrespCountry=GENERIC&sourceID=1&sourceCountry=ww&cons=%1$s&navigation=1&g\nenericSiteIdent=",
    "TNT Express (reference)": "http://www.tnt.com/webtracker/tracking.do?requestType=GEN&searchType=REF&respLang=en&r\nespCountry=GENERIC&sourceID=1&sourceCountry=ww&cons=%1$s&navigation=1&gen\nericSiteIdent=",
    "UK Mail": "https://old.ukmail.com/ConsignmentStatus/ConsignmentSearchResults.aspx?SearchType=Reference&SearchString=%1$s"
  },
  "United States": {
    "Fedex": "http://www.fedex.com/Tracking?action=track&tracknumbers=%1$s",
    "FedEx Sameday": "https://www.fedexsameday.com/fdx_dotracking_ua.aspx?tracknum=%1$s",
    "OnTrac": "http://www.ontrac.com/trackingdetail.asp?tracking=%1$s",
    "UPS": "http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=%1$s",
    "USPS": "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=%1$s"
  }
}
@mridulcse
Copy link

I how can I use it in my website, i am new to wp rest api

@gedex
Copy link
Author

gedex commented Jun 14, 2019

@LucSpan can try with curl first? The gist above contains example request with curl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment