Skip to content

Latest commit

 

History

History
103 lines (75 loc) · 2.92 KB

china-post-tracking-api-python.md

File metadata and controls

103 lines (75 loc) · 2.92 KB

China Post Tracking API - Python

Use Python to track China Post shipments with China Post Tracking API.

Features

  • Real-time China Post tracking.
  • Batch China Post tracking.
  • Other features to manage your China Post tracking.

Installation

Installation is easy:

$ pip install trackingmore-sdk-python

Quick Start

Get the API key:

To use this API, you need to generate your API key.

  • Click here to access TrackingMore admin.
  • Go to the "Developer" section.

  • Click "Generate API Key".

  • Give a name to your API key, and click "Save" .

Then, start to track your China Post shipments.

Usage

Create a tracking (Real-time tracking):

  import trackingmore
  trackingmore.api_key = 'your api key'
  
  try:
    params = {'tracking_number': 'EE950677712TW','courier_code':'china-post'}
    result = trackingmore.tracking.create_tracking(params)
    print(result)
  except trackingmore.exception.TrackingMoreException as ce:
    print(ce)
  except Exception as e:
    print("other error:", e) 

Create trackings (Max. 40 tracking numbers create in one call):

import trackingmore
trackingmore.api_key = 'your api key'

try:
  params = [
    {'tracking_number': 'RG022754039CN', 'courier_code': 'china-post'},
    {'tracking_number': 'AM247540919CN', 'courier_code': 'china-post'}
  ]
  result = trackingmore.tracking.batch_create_trackings(params)
  print(result)
except trackingmore.exception.TrackingMoreException as ce:
  print(ce)
except Exception as e:
  print("other error:", e) 

Get status of the shipment:

import trackingmore
trackingmore.api_key = 'your api key'

try:
  # Perform queries based on various conditions
  # params = {'courier_code': 'china-post'}
  # params = {'tracking_numbers': 'AM247540919CN,RG022754039CN', 'courier_code': 'china-post'}
  params = {'created_date_min': '2023-08-23T06:00:00+00:00', 'created_date_max': '2023-09-05T07:20:42+00:00'}
  result = trackingmore.tracking.get_tracking_results(params)
  print(result)
except trackingmore.exception.TrackingMoreException as ce:
  print(ce)
except Exception as e:
  print("other error:", e) 

Update a tracking by ID:

import trackingmore
trackingmore.api_key = 'your api key'

params = {'customer_name': 'New name', 'note': 'New tests order note'}
id_string = "99e6cc563ad7533c56262b104007e751"
try:
  result = trackingmore.tracking.update_tracking_by_id(id_string, params)
  print(result)
except trackingmore.exception.TrackingMoreException as ce:
  print(ce)
except Exception as e:
  print("other error:", e)