import requests
import json
AUTH = 'login', 'pass'
def api(path, data={}, method=requests.get):
result = method(
'https://rest.websupport.sk/v1/%s' % path,
headers={'Content-type': 'application/json', 'Accept': 'application/json'},
auth=AUTH, data=json.dumps(data)
)
try:
if result.status_code >= 400:
raise Exception(result.json()['message'])
return result.json()
except (ValueError, KeyError):
raise Exception(result.text)
try:
print api('user/self')
except Exception as e:
print e.message
try:
print api('user/self/order', {
"services": [
{'type': 'domain', 'domain': 'newdomain.com'}
]
}, method=requests.post)
except Exception as e:
print e.message