Sample call in Python?

Sure would appreciate a sample call inside of Python …

Here is what I am trying using python3 and it’s not successful (tokens and such changed of course)

import requests
import json

posturl = 'https://troop-abc.trooptrack.com:443/api/v1/tokens
postdata = {“X-Partner-Token” : “g_fancytokenhere”, “X-Username” : “mywebuserid”, “X-User-Password” : “mywebpassword”}

postresponse = requests.post(posturl, data=postdata)
print (postresponse.text)

Everytime I get:
{“error”:“401 Unauthorized partner”}

Of course it works on the swagger page.

My goal is to be able to build some more usable User reports until such a time as TT can get them added.

Hi @troop200bsa,

It looks to me like you are sending the authentication headers in the payload of the post, instead of in the headers. And that’s why it is not working.

Thanks!

That did it, thank you. By default returns json

import requests
import json

posturl = 'https://troop-abc.trooptrack.com:443/api/v1/tokens
postheaders = {‘X-Partner-Token’ : ‘tokenhere’, ‘X-Username’ : ‘login’, ‘X-User-Password’ : ‘password’}

postresponse = requests.post(posturl, headers=postheaders)
print (postresponse.text)

See also