Skip to content

Instantly share code, notes, and snippets.

@joakimsk
Created June 19, 2017 22:09
Show Gist options
  • Save joakimsk/071043e6dd007620196876fa575ae34e to your computer and use it in GitHub Desktop.
Save joakimsk/071043e6dd007620196876fa575ae34e to your computer and use it in GitHub Desktop.
Poweroffice Go API REST test in python3
#!/usr/bin/env python3
import requests
from pprint import pprint
client_id = r'REPLACEME' #Application key
client_secret = r'REPLACEME' #Client key
oauth_token_base_url = 'https://godemo.poweroffice.net/OAuth/Token'
api_base_url = 'https://api-demo.poweroffice.net/'
def _url(path):
return api_base_url + path
def get_access_token():
headers = {'content-type':'application/x-www-form-urlencoded', 'charset':'utf-8'}
payload = {'client_id': client_id, 'grant_type': 'client_credentials', 'client_secret': client_secret}
resp = requests.post(url=oauth_token_base_url,data=payload, headers=headers)
if resp.status_code != 200:
exit("Wrong status:", resp.status_code)
else:
data_json = resp.json()
return data_json
def get_customer():
access_token = get_access_token()['access_token']
#expires_in = data_resp['expires_in']
#refresh_token = data_resp['refresh_token']
#token_type = data_resp['token_type']
access_token_header = {'authorization': 'bearer ' + access_token, 'content-type': 'application/json'}
resp = requests.get(url=_url('/customer/'), headers=access_token_header)
if resp.status_code != 200:
exit("Wrong status:", resp.status_code)
else:
data_json = resp.json()
pprint(data_json)
return
if __name__ == '__main__':
print("poweroffice start")
get_customer() # gets all customers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment