The Python SDK of Trackingmore API
Project description
trackingmore-sdk-python
The Python SDK of Trackingmore API
Contact: manage@trackingmore.org
Official document
Supported Python Versions
- 3.7
- 3.8
- 3.9
- 3.10
- pypy3
Index
Installation
$ pip install trackingmore
Via source code
Download the code archive, without unzip it, go to the source root directory, then run:
$ pip install trackingmore-sdk-python.zip
Quick Start
import trackingmore
trackingmore.api_key = 'you api key'
couriers = trackingmore.courier.get_all_couriers()
Testing
pytest
Error handling
Throw by the new SDK client
import trackingmore
trackingmore.api_key = ''
try:
couriers = trackingmore.courier.get_all_couriers()
print(couriers)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
# API Key is missing
Throw by the parameter validation in function
import trackingmore
trackingmore.api_key = 'you api key'
try:
params = {'tracking_number': ''}
couriers = trackingmore.courier.detect(params)
print(couriers)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
# Tracking number cannot be empty
Examples
Couriers
Return a list of all supported couriers.
https://api.trackingmore.com/v4/couriers/all
try:
result = trackingmore.courier.get_all_couriers()
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Return a list of matched couriers based on submitted tracking number.
https://api.trackingmore.com/v4/couriers/detect
params = {'tracking_number': '92612903029511573030094547'}
try:
result = trackingmore.courier.detect(params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Trackings
Create a tracking.
https://api.trackingmore.com/v4/trackings/create
try:
params = {'tracking_number': '92612903029511573030094547','courier_code':'usps'}
result = trackingmore.tracking.create_tracking(params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Get tracking results of multiple trackings.
https://api.trackingmore.com/v4/trackings/get
try:
# Perform queries based on various conditions
# params = {'tracking_numbers': '92612903029511573030094547', 'courier_code': 'usps'}
# params = {'tracking_numbers': '92612903029511573030094547,92612903029511573030094548', 'courier_code': 'usps'}
params = {'created_date_min': '2023-08-23T14:00:00+08:00', 'created_date_max': '2023-08-23T15:04:00+08:00'}
result = trackingmore.tracking.get_tracking_results(params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Create multiple trackings (Max. 40 tracking numbers create in one call).
https://api.trackingmore.com/v4/trackings/batch
try:
params = [{'tracking_number': '92612903029511573030094593', 'courier_code': 'usps'},
{'tracking_number': '92612903029511573030094594', 'courier_code': 'usps'}]
result = trackingmore.tracking.batch_create_trackings(params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Update a tracking by ID.
https://api.trackingmore.com/v4/trackings/update/{id}
params = {'customer_name': 'New name', 'note': 'New tests order note'}
id_string = "9a2f732e29b5ed2071d4cf6b5f4a3d19"
try:
result = trackingmore.tracking.update_tracking_by_id(id_string, params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Delete a tracking by ID.
https://api.trackingmore.com/v4/trackings/delete/{id}
id_string = "9a2f7d1e8b912b729388c5835c188c28"
try:
result = trackingmore.tracking.batch_create_trackings(params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Retrack expired tracking by ID.
https://api.trackingmore.com/v4/trackings/retrack/{id}
id_string = "9a2f7d1e8b912b729388c5835c188c28"
try:
result = trackingmore.tracking.retrack_tracking_by_id(id_string)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Air Waybill
Create an air waybill.
https://api.trackingmore.com/v4/awb
params = {'awb_number': '235-69030430'}
try:
result = trackingmore.air_waybill.create_an_air_waybill(params)
print(result)
except trackingmore.exception.TrackingMoreException as ce:
print(ce)
Response Code
Trackingmore uses conventional HTTP response codes to indicate success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that resulted from the provided information (e.g. a required parameter was missing, a charge failed, etc.), and codes in the 5xx range indicate an TrackingMore's server error.
Http CODE | META CODE | TYPE | MESSAGE |
---|---|---|---|
200 | 200 | Success |
Request response is successful |
400 | 400 | BadRequest |
Request type error. Please check the API documentation for the request type of this API. |
400 | 4101 | BadRequest |
Tracking No. already exists. |
400 | 4102 | BadRequest |
Tracking No. no exists. Please use 「Create a tracking」 API first to create shipment. |
400 | 4103 | BadRequest |
You have exceeded the shipment quantity of API call. The maximum quantity is 40 shipments per call. |
400 | 4110 | BadRequest |
The value of tracking_number is invalid. |
400 | 4111 | BadRequest |
Tracking_number is required. |
400 | 4112 | BadRequest |
Invalid Tracking ID. |
400 | 4113 | BadRequest |
Retrack is not allowed. You can only retrack an expired tracking. |
400 | 4120 | BadRequest |
The value of courier_code is invalid. |
400 | 4121 | BadRequest |
Cannot detect courier. |
400 | 4122 | BadRequest |
Missing or invalid value of the special required fields for this courier. |
400 | 4130 | BadRequest |
The format of Field name is invalid. |
400 | 4160 | BadRequest |
The awb_number is required or invaild format. |
400 | 4161 | BadRequest |
The awb airline does not support yet. |
400 | 4190 | BadRequest |
You are reaching the maximum quota limitation, please upgrade your current plan. |
401 | 401 | Unauthorized |
Authentication failed or has no permission. Please check and ensure your API Key is correct. |
403 | 403 | Forbidden |
Access prohibited. The request has been refused or access is not allowed. |
404 | 404 | NotFound |
Page does not exist. Please check and ensure your link is correct. |
429 | 429 | TooManyRequests |
Exceeded API request limits, please try again later. Please check the API documentation for the limit of this API. |
500 | 511 | ServerError |
Server error. Please contact us: service@trackingmore.org. |
500 | 512 | ServerError |
Server error. Please contact us: service@trackingmore.org. |
500 | 513 | ServerError |
Server error. Please contact us: service@trackingmore.org. |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for trackingmore_sdk_python-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e6c5dfbd4f485719db53388996ec5c3341918cb714a75498f8f73ed07300b6 |
|
MD5 | 3d854252e8617966d3c3de5e46b410d0 |
|
BLAKE2b-256 | 13fe9d35ee3df898e5b6a88adaa255c3f7f1c6eb380b6a75f41db72bde8a6b55 |
Hashes for trackingmore_sdk_python-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5a61dcbc5168234eaf6d79b34e7da99df4736c137c1c2ff453a9bec8dac3aaa |
|
MD5 | f80e05ddbd2550d022ff198a85fb2025 |
|
BLAKE2b-256 | c52d66d0d1037eb28e14c9fc80e010e35faa5fb4215fc6348cc1770624cd82fb |