-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiTest.py
36 lines (27 loc) · 885 Bytes
/
apiTest.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
import yaml
import base64
import requests
import json
ordersURL = "https://ssapi.shipstation.com/orders"
# Loading configurations
with open('shipstation.yaml', 'r') as stream:
try:
config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print ("Error while loading YAML.")
apiKey = config['user']
apiSecret = config['token']
apiAuth = "{}:{}".format(apiKey, apiSecret)
apiAuth = base64.b64encode(apiAuth.encode('utf-8'))
apiAuth = "Basic {}".format(str(apiAuth, 'utf-8'))
payload = {}
payload['orderStatus'] = 'awaiting_shipment'
headers = {
'Host': 'ssapi.shipstation.com',
'Authorization': apiAuth
}
# Note: Don't delete: data is for posts and params is for gets
request = requests.request("GET", ordersURL, headers=headers, params=payload)
data = json.loads(request.text)
with open('data.json', 'w') as f:
json.dump(data, f, indent=3)