|
1 | | -# tracking-sdk-python |
2 | | -Trackingmore API python sdk |
| 1 | +Trackingmore-Python-sdk |
| 2 | +================= |
| 3 | + |
| 4 | +The Python SDK of Trackingmore API |
| 5 | +## Official document |
| 6 | + |
| 7 | +[Document](https://www.trackingmore.com/v3/api-index) |
| 8 | + |
| 9 | +##Init |
| 10 | + |
| 11 | +``` |
| 12 | + apiKey = "you api Key" |
| 13 | + tracker = trackApi.TrackingApi(apiKey) |
| 14 | +``` |
| 15 | + |
| 16 | +Quick Start |
| 17 | +-------------- |
| 18 | +- Put your ApiKey in the constructor of the Api class |
| 19 | +- All returns are in Json format. |
| 20 | +- After instantiating the Api class, you can use its interface methods |
| 21 | +- You can set the sandbox of the Api instance to true to turn on the sandbox mode: <code>tracker.sandbox=true;</code> |
| 22 | +- Most Api params receive multiple tracking numbers |
| 23 | + |
| 24 | +**Get a list of the couriers in Trackingmore** |
| 25 | + |
| 26 | + result = tracker.doRequest("carriers") |
| 27 | + print(json.loads(result.decode('utf-8'))) |
| 28 | + |
| 29 | +**Detect which couriers defined in your account match a tracking number** |
| 30 | + |
| 31 | + post = { "tracking_number": 'EA152563254CN' } |
| 32 | + postData = json.dumps(postData) |
| 33 | + result = tracker.doRequest("detect", post, "POST") |
| 34 | + print(json.loads(result.decode('utf-8'))) |
| 35 | + |
| 36 | + |
| 37 | +**Post trackings to your account** |
| 38 | + |
| 39 | + //Create single tracking numbers |
| 40 | + post_data = {"tracking_number": "EA152563254CN", "courier": "china-ems"} |
| 41 | + //Create multiple tracking numbers |
| 42 | + postData = [{"tracking_number": "EA152563254CN", "courier": "china-ems"}, {"tracking_number": "EA152563254CN", "courier": "china-ems"}] |
| 43 | + postData = json.dumps(postData) |
| 44 | + result = tracker.doRequest("create", postData, "POST") |
| 45 | + print(json.loads(result.decode('utf-8'))) |
| 46 | + |
| 47 | +**Summary of Connection API Methods with all the api and Methods** |
| 48 | + |
| 49 | + # tracker.sandbox = True |
| 50 | + postData = [{"tracking_number": "EA152563254CN", "courier": "china-ems"}, {"tracking_number": "EA152563254CN", "courier": "china-ems"}] |
| 51 | + postData = json.dumps(postData) |
| 52 | + # Get realtime tracking results of a single tracking |
| 53 | + # post = {"tracking_number": "UB209300714LV", "courier": "cainiao"} |
| 54 | + # result = tracker.doRequest("realtime", json.dumps(post), "POST") |
| 55 | + # print(json.loads(result.decode('utf-8'))) |
| 56 | + |
| 57 | + # count |
| 58 | + # count = "count?courier=1&limit=100&created_at_min=1521314361&created_at_max=1541314361" |
| 59 | + # result = tracker.doRequest(count) |
| 60 | + # print(json.loads(result.decode('utf-8'))) |
| 61 | + |
| 62 | + # # Get tracking results of a tracking or List all trackings |
| 63 | + # get = "get?page=1&limit=100&created_at_min=1521314361&created_at_max=1541314361" |
| 64 | + # result = tracker.doRequest(get) |
| 65 | + # print(json.loads(result.decode('utf-8'))) |
| 66 | + |
| 67 | + # # Update Tracking item |
| 68 | + # result = tracker.doRequest("modifyinfo", postData, "PUT") |
| 69 | + # print(json.loads(result.decode('utf-8'))) |
| 70 | + |
| 71 | + # # archive |
| 72 | + # result = tracker.doRequest("archive", postData, "POST") |
| 73 | + # print(json.loads(result.decode('utf-8'))) |
| 74 | + |
| 75 | + # # Delete tracking item |
| 76 | + # result = tracker.doRequest("delete", postData, "DELETE") |
| 77 | + # print(json.loads(result.decode('utf-8'))) |
| 78 | + |
| 79 | + # # create tracking number |
| 80 | + # result = tracker.doRequest("create", postData, "POST") |
| 81 | + # print(json.loads(result.decode('utf-8'))) |
| 82 | + |
| 83 | + # # manual update |
| 84 | + # result = tracker.doRequest("manualupdate", postData, "POST") |
| 85 | + # print(json.loads(result.decode('utf-8'))) |
| 86 | + |
| 87 | + # # remote tracking |
| 88 | + # result = tracker.doRequest("remote", postData, "POST") |
| 89 | + # print(json.loads(result.decode('utf-8'))) |
| 90 | + |
| 91 | + # # Get cost time iterm results |
| 92 | + # result = tracker.doRequest("transittime", postData, "POST") |
| 93 | + # print(json.loads(result.decode('utf-8'))) |
| 94 | + |
| 95 | + # # detect a carriers by tracking number |
| 96 | + # post = { "tracking_number": 'EA152563254CN' } |
| 97 | + # post = json.dumps(post) |
| 98 | + # result = tracker.doRequest("detect", post, "POST") |
| 99 | + # print(json.loads(result.decode('utf-8'))) |
| 100 | + |
| 101 | + # # get all carriers |
| 102 | + # result = tracker.doRequest("carriers") |
| 103 | + # print(json.loads(result.decode('utf-8'))) |
| 104 | + |
| 105 | + # # Get status number |
| 106 | + # status = "status?tracking_number=EA152563254CN" |
| 107 | + # result = tracker.doRequest(status) |
| 108 | + # print(json.loads(result.decode('utf-8'))) |
| 109 | + |
| 110 | + # # Set number not update |
| 111 | + # result = tracker.doRequest("notupdate", postData, "POST") |
| 112 | + # print(json.loads(result.decode('utf-8'))) |
| 113 | + |
| 114 | + # # Modify courier code |
| 115 | + # post = {"tracking_number": "EA152563254CN", "courier": "china-ems", "new_express": "china-post"} |
| 116 | + # post = json.dumps(post) |
| 117 | + # result = tracker.doRequest("modifycourier", post, "PUT") |
| 118 | + # print(json.loads(result.decode('utf-8'))) |
| 119 | + |
| 120 | +## Typical Server Responses |
| 121 | + |
| 122 | +We will respond with one of the following status codes. |
| 123 | + |
| 124 | +Code|Type | Message |
| 125 | +----|--------------|------------------------------- |
| 126 | +200 | <code>Success</code>| Request response is successful |
| 127 | +203 | <code>PaymentRequired</code>| API service is only available for paid account Please subscribe paid plan to unlock API services ul |
| 128 | +204 | <code>No Content</code>| Request was successful, but no data returned Tracking NO. or target data possibly do not exist |
| 129 | +400 | <code>Bad Request</code>| Request type error Please check the API documentation for the request type of this API |
| 130 | +401 | <code>Unauthorized</code>| Authentication failed or has no permission Please check and ensure your API Key is correct |
| 131 | +403 | <code>Bad Request</code>| Page does not exist Please check and ensure your link is correct ul |
| 132 | +404 | <code>Not Found</code>| Page does not exist Please check and ensure your link is correct |
| 133 | +408 | <code>Time Out</code>| Request timeout The official website did not return data, please try again later |
| 134 | +411 | <code>Bad Request</code>| Specified request parameter length exceeds length limit Please check and ensure that the request parameters are of the required length |
| 135 | +412 | <code>Bad Request</code>| Specified request parameter format doesn't meet requirements Please check and ensure that the request parameters are in the required format |
| 136 | +413 | <code>Out limited</code>| The number of request parameters exceeds the limit Please check the API documentation for the limit of this API |
| 137 | +417 | <code>Bad Request</code>| Missing request parameters or request parameters cannot be parsed Please check and ensure that the request parameters are complete and correctly formatted |
| 138 | +421 | <code>Bad Request</code>| Some of required parameters are empty Some couriers need special parameters to track logistics information (Special Couriers) |
| 139 | +422 | <code>Bad Request</code>| Unidentifiable courier code Please check and ensure that the courier code are correct(Courier code) |
| 140 | +423 | <code>Bad Request</code>| Tracking No. already exists |
| 141 | +424 | <code>Bad Request</code>| Tracking No. no exists Please use 「Create trckings」 API first to create trackings |
| 142 | +429 | <code>Bad Request</code>| Exceeded API request limits, please try again later Please check the API documentation for the limit of this API |
| 143 | +511 | <code>Server Error</code>| Server error Please contact us: service@trackingmore.org. |
| 144 | +512 | <code>Server Error</code>| Server error Please contact us: service@trackingmore.org. |
| 145 | +513 | <code>Server Error</code>| Server error Please contact us: service@trackingmore.org. |
0 commit comments