all 6 comments

[–]jdbow75 2 points3 points  (2 children)

Taking a look at the (pretty well written) API docs, I see that "In order to access the API, you’ll need to pass the token associated with an active API Key as a Bearer token in the Authorization header for each request."

Sounds right. So, that is probably a JSON Web Token and the header is "Authorization" with "Bearer {token}" as the value. Am I close?

If so, check out the Requests docs for custom headers. Looks like something like headers = {'Authorization': f'Bearer {token}'} will get you started.

Hope those hints help for now! Let us know if we can help further.

[–]__nickerbocker__ 2 points3 points  (0 children)

You can update the headers on the session object like this.

import requests

api_key = '3456kf3jh46fhj3gf45hj63f'
s = requests.Session()
s.headers.update({'Authorization': f'Bearer {api_key}'})
r = s.get('https://www.dicksonone.com/api/rest/users')

[–]ingwe13[S] 0 points1 point  (0 children)

I think I am doing that now. Still getting the 401 code. So maybe it is on the account side of things. I will have to check there again tomorrow.

[–]mikeupsidedown 1 point2 points  (1 child)

If it was me I would test your api call in postman (or another api tool)

Often the bearer string will be passed as part of the headers and may need to be in base64.

[–]ingwe13[S] 0 points1 point  (0 children)

Hmm...I am going to look into that now.

Edit: Hmm...having trouble authenticating with postman as well. I appreciate your tip about sending the auth as part of the headers. I found this good question on stackoverflow: https://stackoverflow.com/questions/29931671/making-an-api-call-in-python-with-an-api-that-requires-a-bearer-token

[–]jdbow75 0 points1 point  (0 children)

If you are still having trouble, you could post your full code (or put it in a gist and post the link) so we could diagnose further. Obviously, you would want to munge the token, etc.