-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv1_example.py
65 lines (48 loc) · 1.84 KB
/
v1_example.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
54
55
56
57
58
59
60
61
62
63
64
65
import json
import requests
import time
def getItemList(url, token):
headers = {'Content-type': 'application/json; charset=utf-8',
'Authorization': 'Token ' + str(token)}
response = requests.get(url, jsondata, headers = headers)
return response.json()
def getDetailItem(url, token):
url = url + 'pen'
headers = {'Content-type': 'application/json; charset=utf-8',
'Authorization': 'Token ' + str(token)}
response = requests.get(url, jsondata, headers = headers)
return response.json()
def getAvailableItem(url, token):
url = url + "?avail=1"
headers = {'Content-type': 'application/json; charset=utf-8',
'Authorization': 'Token ' + str(token)}
response = requests.get(url, jsondata, headers = headers)
return response.json()
def purchaseItem(url, token):
body={ 'title': 'pen', 'quantity':10 }
headers = {'Content-type': 'application/json; charset=utf-8',
'Authorization': 'Token ' + str(token)}
jsondata = json.dumps(body)
response = requests.post(url, jsondata, headers = headers)
#v1 example
if __name__=="__main__":
#first get auth token
username = 'shopify'
password = 'testing12'
url = "http://shopify-janujan.herokuapp.com/api-token-auth/"
body = { 'username':username , 'password':password }
jsondata = json.dumps(body)
headers = {'Content-type': 'application/json; charset=utf-8'}
response = requests.post(url, jsondata, headers = headers)
token = response.json()['token']
print(token)
url = "http://shopify-janujan.herokuapp.com/commerce/v1/"
items = getItemList(url, token)
print(items)
item = getDetailItem(url, token)
print(item)
items = getAvailableItem(url, token)
print(items)
#purchaseItem(url, token)
#items = getItemList(url, token)
#print(items)