Check on Tracking

After your job has been processed you can check on the shipment tracking by doing a GET call on the /jobs/{id}/Tracking endpoint using the ID returned from the /jobs call that created the job. This is an optional call that you can also check through the website as well, even if you submitted your job via API.

Important The tracking information is only provided back to Click2Mail once per day so calling it once per day is sufficient to get the most up to date information.

Note In the staging environment the API will never return tracking details as the items are never actually sent.

The one required parameter is trackingType, which we will set to 'IMB' for this tutorial. Acceptable values are 'IMB' meaning Intelligent Mail Barcode, and 'IMPB' meaning Intelligent Mail Package Barcode.

Important trackingType is a QUERY parameter, so must be specified within the URL.

An optional parameter is to specify the desire for tracking details. By default this value is set to false.

The following code sample demonstrates requesting tracking information for job ID 8675309:

# Load the HTTP requests module
import requests

# Define credentials
myusername = 'awesomeuser'
mypassword = 'gReAt/PaSsWoRd123'

headers = {'user-agent': 'my-app/0.0.1'}

# Note the ID of the previously-created job
jobId = '8675309'

# Set the tracking for the job
trackingType = "trackingType=IMB"

# Define the endpoint to use, including the jobId
url = "https://stage-rest.click2mail.com/molpro/jobs/" + jobId + "/tracking?" + trackingType

# Make the GET call
r = requests.get(url, headers=headers, auth=(myusername, mypassword))

# Display the result - a success should return status_code 201
print(r.status_code)

# Display the full XML returned.
print(r.text)

If the GET call is successful, it will return an HTTP status code of 201, along with an XML body containing tracking information about the mail pieces within the job:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<job>
  <id>8675309</id>
  <status>0</status>
  <description>Success</description>
  <tracking>
    <mailPiece>
      <barCode>00270200802005045061</barCode>
      <address>Awesome User,715 S Calhoun St,Fort Wayne,IN,46802</address>
      <status>Printed</status>
      <dateTime>2021-12-22 20:32:02.0</dateTime>
      <statusLocation>FLINT,MI</statusLocation>
    </mailPiece>
  </tracking>
  <statusUrl>https://stage-rest.click2mail.com/molpro/jobs/485194/trackingtracking?trackingType=IMB&amp;trackingType=IMB</statusUrl>
</job>