import requests import json def login(): loginUrl = "https://trybindo.com/api/v2/login" head = { 'Accept': 'application/json, text/plain, */*', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Connection': 'keep-alive', 'Content-Length': '139', 'Content-Type': 'application/json', 'Host': 'trybindo.com', 'Origin': 'https://dashboard.trybindo.com', 'Referer': 'https://dashboard.trybindo.com/login', 'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'X-Application': 'dashboard.trybindo.com' } body = { "password":"w111111", "username":"paul.wang@bindo.com" } r = requests.post(loginUrl,json=body,headers=head,verify=False) print('================login api :======================== ') print(r.status_code) print(r.text) print(type(r)) print(r.json()['user']['access_token']) print(type(r.json()['user']['access_token'])) token=r.json()['user']['access_token'] return token def getcustomers(): host='https://trybindo.com' url=host+'/api/v2/stores/6889/customers?order_asc=desc&order_by=updated_at&page=1&per_page=25' headx={} headx['X-USER-ACCESS-TOKEN']=login() r = requests.get(url,headers=headx) print("===============customers api=================") print(r.status_code) print(r.text) assert r.status_code==200 assert 'store_id' in r.text def getmyinvoice(): host='https://gateway.trybindo.com' url=host+'/v2/order_correspondences?store_ids=6272&order_asc=desc&order_by=updated_at&page=1&per_page=25' headx={} headx['X-USER-ACCESS-TOKEN']=login() body={ 'store_ids':'6272', 'order_asc':'desc', 'order_by':'updated_at', 'page':'1', 'per_page':'25' } r = requests.get(url,headers=headx,json=body,verify=False) print("===============get my invoice id and order number api=================") print(r.status_code) # print(r.text) myOrder=r.json()['order_correspondences'][0] print('my order id is: %d' %myOrder['id']) print(myOrder['number']) print(myOrder) # assert r.status_code==200 def getinvoicecheck(): # host='https://gateway.trybindo.com' url='https://gateway.trybindo.com/v2/stores/6865/invoices/201809261232227763170019/check' headx={} headx['X-USER-ACCESS-TOKEN']=login() print(headx['X-USER-ACCESS-TOKEN']) r = requests.get(url,headers=headx,verify=False) print("===============get test api3=================") print(r.status_code) print(r.text) def getlistingsupplier(): url='https://trybindo.com/api/v2/stores/7090/listings/25102690/with_suppliers' headx={} headx['X-USER-ACCESS-TOKEN']=login() # print(headx['X-USER-ACCESS-TOKEN']) r = requests.get(url,headers=headx,verify=False) print("===============get test api4=================") print(r.status_code) print(r.text) def getlistingmembers(): url='https://trybindo.com/api/v2/stores/7090/listings/25102690/with_members' headx={} headx['X-USER-ACCESS-TOKEN']=login() # print(headx['X-USER-ACCESS-TOKEN']) r = requests.get(url,headers=headx,verify=False) print("===============get test api5=================") print(r.status_code) print(r.text) def getlistingsearch(): url='https://trybindo.com/api/v2/listings/search' body={"search":{"filter":{"store_id":[7090]},"sort":[{"created_at":"desc"}]},"per_page":25,"page":1} headx={} headx['X-USER-ACCESS-TOKEN']=login() # print(headx['X-USER-ACCESS-TOKEN']) r = requests.post(url,headers=headx,json=body,verify=False) print("===============get test api6=================") print(r.status_code) print(r.text) def editlisting(): url='https://trybindo.com/api/v2/stores/7090/listings/25102786' body={"listing":{"name":"abc","kitchen_department_id":"","modifier_set_ids":[],"tax_option_ids":[],"product_translations":[],"price_options":[],"custom_field_values":[],"variants":[],"suppliers":[],"serial_numbers":[],"listing_reference_codes":[{"id":'66277',"listing_id":"25102786","code":"11111111111111","created_by_id":'13298',"error":'null'}],"procurement_methods":{"dine_in":'false',"pickup":'false',"delivery":'false',"dine_in_unassigned":'false'},"_product_translation_map":{},"quantity":'0',"modifier_group_ids":[]}} headx={} headx['X-USER-ACCESS-TOKEN']=login() # print(headx['X-USER-ACCESS-TOKEN']) r = requests.put(url,headers=headx,json=body,verify=False) print("===============get test api7=================") print(r.status_code) print(r.text) def deletelisting(): url='https://trybindo.com/api/v2/stores/7090/listings/25102783' headx={} headx['X-USER-ACCESS-TOKEN']=login() # print(headx['X-USER-ACCESS-TOKEN']) r = requests.delete(url,headers=headx,verify=False) print("===============get test api8=================") print(r.status_code) print(r.text) def main(): # getcustomers() getmyinvoice() # getinvoicecheck() # getlistingsupplier() # getlistingmembers() # getlistingsearch() # editlisting() # deletelisting() if __name__=='__main__': main()