[Resolved] Dhan Order API - Invalid Token Error before token expires!

Hi Dhan Team,

I had an issue today where when I placed an order through my custom ordering app (Tried and Tested, working fine!), the following error/response was thrown:

{‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘RS-9005’, ‘message’: ‘Invalid Token’}, ‘data’: ‘’}

Now my token was a 30-day token and was valid for several more day! I retrieve and save token in a full-proof manner, and also cross checked. There was no mistake in token. I was able to resolve the issue by generating a new token on dhan webapp, but the trading opportunity was gone by then.

This has happened once before too, few months back. What is the backend issue going on with this? Please check and respond as missing trade opportunities keeps me from trading on Dhan. You already do not provide LTP API calls which is a huge drawback. Nevertheless, please provide resolution to this!

Thanks,
DJ (cc id: 1101294818 )

1 Like

Hello @Djain

Will check this once on our end, but this shouldn’t happen. All access tokens are JWT on Dhan APIs. Can you DM me the time when this happened and if you have the last few digits of the token?

Also, was the token showing valid on DhanHQ API Access Token panel when you visited the same?

Hi @Hardik
The last few digits are " 3Asko0Mw "
The issue happened at around 22:15-22:30 on 24th Jul 2024. Sorry I do not have the exact timestamp. The instrument was NATURALGASM AUG FUT.
After this issue, I checked the API web page. The token was showing as “Active” and had around 20 days as Time to expiry. I deleted that token and created a new one. That worked. It has happened few weeks back also.

Thanks,
DJ ( c id: 1101294818 )

Hello @Djain

We are looking into this. This is not intended, but will definitely do a troubleshoot here.

Same thing is happening again and again with me too. It keeps saying “Invalid token” when i try execute any call as simple as get_order_list or positions just to debug even. My token is created for 30 days expiry while this happens even after 1 day. Right now i created a new token and that works. This is crazy, there are soo many things about dhan api which seems so unreliable, please make it robust and work properly please.
output I was getting
{‘status’: ‘failure’,
‘remarks’: {‘error_code’: ‘DH-906’,
‘error_type’: ‘Order_Error’,
‘error_message’: ‘Invalid Token’},
‘data’: {‘errorType’: ‘Order_Error’,
‘errorCode’: ‘DH-906’,
‘errorMessage’: ‘Invalid Token’}}

Hello @Msk92

We checked this and it shouldn’t be happening. There was a one-time issue that was highlighted by @Djain. Can you check the validity at your end while generating the token.