-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathups.py
52 lines (37 loc) · 1.03 KB
/
ups.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
import requests
import os
from dotenv import load_dotenv
load_dotenv()
url = "https://onlinetools.ups.com/security/v1/oauth/token"
client_id = os.getenv('ups_id')
client_pass = os.getenv('ups_pass')
def getToken():
payload = {
"grant_type": "client_credentials"
}
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"x-merchant-id": "string"
}
response = requests.post(url, data=payload, headers=headers, auth=(client_id,client_pass))
data = response.json()
return data['access_token']
def trackshipment():
token = getToken()
inquiry_number = "1Z1202R66698804005"
url = "https://onlinetools.ups.com/api/track/v1/details/" + inquiry_number
query = {
"locale": "en_US",
"returnSignature": "false",
"returnMilestones": "false",
"returnPOD": "false"
}
headers = {
"transId": "string",
"transactionSrc": "testing",
"Authorization": "Bearer " + token
}
response = requests.get(url, headers=headers, params=query)
data = response.json()
print(data)
trackshipment()