This repository was archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathtracking.py
53 lines (41 loc) · 1.7 KB
/
tracking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import shippo
'''
In this tutorial we have an order with a sender address,
recipient address and parcel information that we need to ship.
'''
# Replace <API-KEY> with your key
shippo.config.api_key = "<API-KEY>"
# Tracking based on a Shippo transaction
transaction_id = '<TRANSACTION-ID>'
transaction = shippo.Transaction.retrieve(transaction_id)
if transaction:
print(transaction.get('tracking_status'))
print(transaction.get('tracking_history'))
# Tracking based on carrier and tracking number
tracking_number = '9205590164917337534322'
# For full list of carrier tokens see https://goshippo.com/docs/reference#carriers
carrier_token = 'usps'
tracking = shippo.Track.get_status(carrier_token, tracking_number)
print(tracking)
# Create a webhook endpoint (FYI-basic auth not supported)
# For a full list of Webhook Event Types see https://goshippo.com/docs/webhooks/
new_webhook_response = shippo.Webhook.create(url='https://exampledomain.com',event='all')
print(new_webhook_response)
# list webhook(s)
webhook_list = shippo.Webhook.list_webhooks()
print(webhook_list)
# remove all webhooks
for webhook in webhook_list['results']:
print("about to delete webhook {}".format(webhook['object_id']))
webhook_remove = shippo.Webhook.delete(object_id=webhook['object_id'])
# print empty 204 status
print(webhook_remove)
# Registering a tracking number for webhook
webhook_response = shippo.Track.create(
carrier=carrier_token,
tracking_number=tracking_number,
metadata='optional, up to 100 characters'
)
print(webhook_response)
# For more tutorals of address validation, tracking, returns, refunds, and other functionality, check out our
# complete documentation: https://goshippo.com/docs/