paramatrixtech / ksapi

Kotak Securities Trading APIs Integration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid Credentials

mshh9 opened this issue · comments

commented

Hi,

I followed the instructions to initiate a session as below .

from ks_api_client import ks_api
client = ks_api.KSTradeApi(access_token = "", userid = "", consumer_key = "",ip = "127.0.0.1", app_id = "",
host = "https://tradeapi.kotaksecurities.com/apim", consumer_secret = "")

I have provided my credentials as seen in my "defaultapplication" in the code above but i am facing the following error. I have also tried to regenerate my access token but still no use.

ApiException: (401)
Reason: Unauthorized
HTTP response body: {"fault":{"code":900901,"message":"Invalid Credentials","description":"Access failure for API: /apim/session/1.0, version: 1.0 status: (900901) - Invalid Credentials. Make sure you have provided the correct security credentials"}}

But when i try to test in the session API portal i receive the following response. This response seems like the session initiation was a success. What is it that i am missing. Kindly help.

{'Success': {'clientType': 'ONLINE',
'encryption': {'keySize': 0, 'publickKey': '', 'type': 'PLAIN'},
'isNRI': 'N',
'message': '',
'redirect': {'host': 'https://ctradeapi.kotaksecurities.com/apim',
'port': 443},
'service': {'host': 'https://tradeapi.kotaksecurities.com/apim',
'port': 443},
'status': 'Success',
'userType': 'G',
'userid': 'XXXXXXXX'}}

Hi please pass https://ctradeapi.kotaksecurities.com/apim as your host parameter instead of the default value.

some users are on tradeapi and some are on ctradeapi, which one it is depends on their Datacentre on our backend, and can be deduced by checking the URL of your api webportal account.

commented

Hi Dhwaj,

I tried with ctradeapi but still getting the same error. My web portal account says tradeapi and also the response i get why i test in the sessions API, this is the url i get. Can you please check backend if everything is ok with my account?
'https://tradeapi.kotaksecurities.com/apim/session/1.0/session/init'

commented

Kindly reopen this issue until the issue is resolved.

I see, this might be due to a datacentre issue instead. please send an email to ks.apihelp@kotak.com and we will move your account to the correct datacentre.

commented

I have already mailed them a couple of times but haven't got a response. Can you please help to connect with the Kotak team?

But when i try with the response from the session API and use the 'requests', it works. Does this mean it is a datacentre issue? Because the python SDK wrapper provided is giving the error of invalid credentials.

url below is what is provided in the session API response.

url = 'https://tradeapi.kotaksecurities.com/apim/session/1.0/session/init'
import requests
Bearer = 'Bearer'
headers = {'accept' : 'application/json', 'userid' : userid, 'consumerKey' : consumer_key, 'ip' : '127.0.0.1', 'appID' : consumer_secret, 'Authorization' : Bearer + " " + access_token }
client = requests.get(url, headers=headers).json()
client
{'Success': {'clientType': 'ONLINE',
'encryption': {'keySize': 0, 'publickKey': '', 'type': 'PLAIN'},
'isNRI': 'N',
'message': '',
'redirect': {'host': 'https://ctradeapi.kotaksecurities.com/apim',
'port': 443},
'service': {'host': 'https://tradeapi.kotaksecurities.com/apim',
'port': 443},
'status': 'Success',
'userType': 'G',
'userid': 'XXXXXXX'}}

This is most likely due to your datacentre. Im sorry to hear you got no response the last time you reached out. Please send a fresh email to ks.apihelp@kotak.com, and i will ensure that we resolve it asap.
Do mention your User ID or Client Code in the email (also, it will help me to identify it if you mention your github username on the email)

commented

I have mailed along with my user ID and github username. Kindly look into this. Thank you

commented

The issue is resolved. Kotak team changed the datacenter and i am able to login. Thank you for your support.

Glad we could help!