Postman test not working (also python)

4 posts / 0 new
Last post
sohaib94
Postman test not working (also python)

Hi all,

I'm fairly new to programming, so please excuse me for some nooby questions.

I am trying to use postman to test the response I get from POSTing /session (I just want to get the tokens I need).

I've got the url set to demo-api.ig.com/gateway/deal/session/

My header looks like this:
X-IG-API-KEY: MY_API_KEY

And my body looks like this:
identifier: MY_USERNAME
password: MY_PASSWORD

I though this would be enough, but I seem to keep getting back the status code 401 Unauthorised

{
"errorCode": "error.security.client-token-missing"
}

My understanding was that I was calling /session to get a session token, hence why I am confused as to why I get this error message. Am I missing something in the POST?

I was attempting to do this in Python first, with the following code:


import requests
import json

username = MY_USERNAME
password = MY_PASSWORD
api_key = MY_API_KEY
base_url = 'https://demo-api.ig.com/gateway/deal'

headers = {
'X-IG-API-KEY': api_key
}

body = {
'identifier': username,
'password': password
}

resp = requests.post(base_url + '/session', headers=headers, data=body)
print (base_url + '/session')


print(resp.status_code)
print(resp.headers)
print(resp.text)

Which was giving me a 415 error code, which led me to test it in Postman. Could anyone please tell me why the error codes are different, and at the very least how I can fix the error from Postman?

Thanks

andysinclair
Postman test not working (also python)

I have had no problems testing in Postman.

I set the two required headers: X-IG-API-KEY and Content-Type to application/json.

The body of my post request is just my username and password (in JSON format so the quotes are important). I use the Postman "raw" setting for the body:

{
"identifier": "USERNAME",
"password": "PASSWORD"
}

Hope this helps you get it working in Postman, afraid I can't help with Python,

Andy
(andy@coderun.net)

sohaib94
Thanks!

Thanks!

I tried adding Content-Type to the header and copy-pasting your body to my request (with my details) but no luck, I keep getting the same result.

Are you doing a POST request to demo-api.ig.com/gateway/deal/session/ ?

sohaib94
Nevermind! I figured it out :

Nevermind! I figured it out :)

I forgot to start the url with https:// :P

For future reference (and if anyone else is as new as me in this domain) postman can create a code for you in some languages, which you can use and copy into your code to get a successful response. This is what I've done in this case, so got my Python working as well! :D

Log in or register to post comments