authentication - How to use an auth token and submit data using Python requests.POST? -


using wheniwork's api, need use token authentication, , need send data create new user. order or name of arguments send requests.post() matter?

if i'm using pull information, can have url contain thing i'm looking for, , send payload token. example:

url = 'https://api.wheniwork.com/2/users/2450964' payload = {"w-token": "ilovemyboss"} r = requests.get(url, params=payload) print r.text 

when try add new user however, i'm either not able authenticate or not passing data correctly. api reference shows format using curl:

curl https://api.wheniwork.com/2/users --data '{"first_name":"firstname", "last_name": "lastname", "email": "user@email.com"}' -h "w-token: ilovemyboss" 

here's i've written out in python (2.7.10) using requests:

url = 'https://api.wheniwork.com/2/users' data={'first_name':'testfirst', 'last_name':  'testlast','email':'test@aol.com'} params={"w-token": "ilovemyboss"} r = requests.post(url, data=data, params=params) print r.text 

can explain if/how data(the user) gets sent separately authentication(the token)?

i found issue! data (user dict) needs in quotes. i'm not sure if api expecting string, or if that's how requests works, or what. here's solution:

url = 'https://api.wheniwork.com/2/users' data = "{'first_name':'testfirst', 'last_name':  'testlast','email':'test@aol.com'}" params = {"w-token": "ilovemyboss"} r = requests.post(url, data=data, params=params) print r.text 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -