how to create access token more than 24 Hours, I want to create access token atleast for 30 days.
Hey @Shrinath ,
As per new regulation the API access tokens will now be valid for 24 hours only.
Any link?
Read this circular: https://nsearchives.nseindia.com/content/circulars/INVG67858.pdf
Are you referring to this?
All API sessions shall be compulsorily logged out every day before the start of the next trading day
This doesnt require restricting token validity to 24 hours, does it?
Ah yes, got a lil confused, Dhan has been doing it differently until now. With Z and others I already generate the tokens daily.
Correct. They have been doing it like that for a long time, fgot about it as I automated it a long time back ![]()
So Dhan was the odd one out (until now)
@VijayNair how did u automate it, does ypur code run 24/7 with automatic access token generation?
ok it is ok everyday
but we want api to generate access token
we will generate every day without going the website
so it is not right answer
Hey @YashTamrakar ,
You can generate an access token without logging into the website by using the API key and TOTP setup. We have provided a detailed manual steps for the process, which can be found here:
API Key & Secret Setup.
Please note that the automation of this process will need to be handled on your end.
Hello @Shrutika_Poojari, @Dhan @Hardik @Dhan_Cares
Regarding Step 2,
This endpoint needs to be accessed directly through a browser. In this step, the user must log in using their Dhan credentials and complete 2FA verification using an OTP, PIN, or password. Upon successful login, the user is redirected to the callback URL specified during API key generation.
However, this process cannot be fully automated, as the OTP, PIN, and 2FA tokens change dynamically each time.
If there’s a way to make this process more consistent—such as using a static passcode or app-based PIN—please guide us on how this can be implemented.
Note: If this is not possible, we kindly request that this process be reviewed or modified on priority, as the current approach is quite inconvenient and requires frequent token changes, which impacts usability.
Thank you in advance for your support.
Hello @Galbabhai_Kuva
There is a TOTP based login module that you can use, which will not require the need for OTP. We have written more about it here: Update for API Traders: New Changes in DhanHQ API Authentication Process and Updates
Hello @Shrutika_Poojari, @Dhan @Hardik @Dhan_Cares
I understand but still this is not possible via automation. my point here is about step2 which is not fully automated via code.
Those who think step 2 automation is not possible, every request happening between the client and server can be automate.
You just need to capture the REST API calls between the browser and the server.
I’ve already created a thread about this.
https://private-poc.madefortrade.in/t/generate-dhan-token-automatically-with-python/56632/
why not have an API for generating the token with a totp secret ?
AngelOne smartAPI does it, super simple to use.
everything about dhan api is overengineered to highest level without any demand
Does this work with 3rd party like TradeTron? I am using their strategy creation tools and placing order via Dhan. Earlier it was one time activity of API Key updation in 30 days.
Hey @RajivK ,
The access token validity has now been updated to 24 hours as per regulatory requirements.
However, you can still generate a new access token without logging in to Dhan each time by using your API key and secret. Just follow the steps here: Authentication - DhanHQ Ver 2.0 / API Document


