import jwt import os import requests import time ## Create jwt token with open('private_key.pem', 'r') as rsa_priv_file: #Not sure about adding the utf-8 AT ALL priv_rsakey = rsa_priv_file.read() iat = int(time.time()) exp = iat + 600 encoded_jwt = jwt.encode({ "sub": "sys", "iss": "matthew-fleming", "iat": iat, "exp": exp }, priv_rsakey , algorithm='RS256') token = encoded_jwt.decode('utf-8') ## Create Shipper endpoint = "https://api.sandbox.loadsmart.com/api/v2/shippers" data = { "company_name": "Matts New Shipper v2" } headers = {'Content-Type': 'application/json', 'Auth':token} r = requests.post(url = endpoint, headers= headers, json= data) print r cargo = r.json() shipper_id = cargo['data']['id'] ## Create User endpoint = "https://api.sandbox.loadsmart.com/api/v2/shippers/accounts" data = { "shipper_id":str(shipper_id), "email": "admin+supertest@blabb.io" } print data headers = {'Content-Type': 'application/json', 'Auth':token} r = requests.post(url = endpoint, headers= headers, json= data) print r
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question