API Authorization issue

**
Kuber Nath**

15 hours ago

Hello , auth code authorization issues.

Raw Response: 401 {“code”:-16,“message”:“Could not authenticate the user”,“s”:“error”}

Copy

{"error":{"code":-16,"message":"Could not authenticate the user","s":"error"}}

Please share.the solution

Environment Python 3.12 using VS Code

Redirect URI: http://127.0.0.1:5006/callback

Client ID: [Your Client ID]

Like

Reply

Hi @111693808730645307047 ,
We have verified that the authorization endpoints are working fine from our end. The error shared by you indicates that an invalid or expired token is being passed. Kindly regenerate the access token and follow the authorization process as mentioned in the documentation link
https://myapi.fyers.in/docsv3#tag/Authentication-and-Login-Flow-User-Apps/paths/~1Authentication%20&%20Login%20Flow%20-%20User%20Apps/patch

Than y

I am using above URL to Get Auth code .I got redirected to Log iog in page after login I get AUTH code. which I copy to get Token but it wont work and send authorization error as told in earlier thread, verify the URL is correct. and I am getting correct auth code eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfaWQiOiJOMDZRTzVHQVhNIiwidXVpZCI6IjhkZDBiYTk2NDUyOTRjZTg4NGQwOTY2NTJlY2ExODEzIiwiaXBBZGRyIjoiIiwibm9uY2UiOiIiLCJzY29wZSI6IiIsImRpc3BsYXlfbmFtZSI6IkZTMTk3NCIsIm9tcyI6IksxIiwiaHNtX2tleSI6IjhmZTdhMmYxZDAwMGI4MWJhYjQyMWExOTZlZDM5Y2QwNWM0OTE4OTZiZDBkODc2N2E1NzFjNzQ3IiwiaXNEZHBpRW5hYmxlZCI6Ik4iLCJpc010ZkVuYWJsZWQiOiJOIiwiYXVkIjoiW1wiZDoxXCIsXCJkOjJcIixcIng6MFwiLFwieDoxXCIsXCJ4OjJcIl0iLCJleHAiOjE3NjczNjY2OTAsImlhdCI6MTc2NzMzNjY5MCwiaXNzIjoiYXBpLmxvZ2luLmZ5ZXJzLmluIiwibmJmIjoxNzY3MzM2NjkwLCJzdWIiOiJhdXRoX2NvZGUifQ.7XTbqbPwo-K0rviXXG-LOom_TKgR33fhHA4_qnDAxPA

I use this code within few mins FYI…I am creating webhook from Trading view to Fyers API personal APP

I am using above URL to get auth code.After running the URL in browswer it taken to Fyers login page and authenticate and then send auth code which I quicly copy and use for Token genration but agets above authorization error .check the URL is correct and below auth code format is corect which I get to use for Token genration .Auth code eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfaWQiOiJOMDZRTzVHQVhNIiwidXVpZCI6ImM3OGViZjFlODZlODRlOTBiMGRlNjM1ZTNlMWVlYjYxIiwiaXBBZGRyIjoiIiwibm9uY2UiOiIiLCJzY29wZSI6IiIsImRpc3BsYXlfbmFtZSI6IkZTMTk3NCIsIm9tcyI6IksxIiwiaHNtX2tleSI6IjhmZTdhMmYxZDAwMGI4MWJhYjQyMWExOTZlZDM5Y2QwNWM0OTE4OTZiZDBkODc2N2E1NzFjNzQ3IiwiaXNEZHBpRW5hYmxlZCI6Ik4iLCJpc010ZkVuYWJsZWQiOiJOIiwiYXVkIjoiW1wiZDoxXCIsXCJkOjJcIixcIng6MFwiLFwieDoxXCIsXCJ4OjJcIl0iLCJleHAiOjE3NjczNzI0MDksImlhdCI6MTc2NzM0MjQwOSwiaXNzIjoiYXBpLmxvZ2luLmZ5ZXJzLmluIiwibmJmIjoxNzY3MzQyNDA5LCJzdWIiOiJhdXRoX2NvZGUifQ.5W5SFqgbYkCgErtIYAHz5s2Rfd9V1Yve31iUIEClEbk

I am creating webhook to connect Trading view logic to connect with Fryers App for trading.

I am crating webhook for trading between trading view and my Fyers API app using Fyers App. I use below URL to get Auth code after getting auth code immediately I trigger logic to get Token thats when I get the AUth error as above .

I am doing this using Python 3.13

https://api-t1.fyers.in/api/v3/generate-authcode?client_id=MyClientID&redirect_uri=http://127.0.0.1:5005/callback&response_type=code&state=sample_state

I get Raw Response: 401 {“code”:-16,“message”:“Could not authenticate the user”,“s”:“error”}

Parsed JSON: {‘code’: -16, ‘message’: ‘Could not authenticate the user’, ‘s’: ‘error’}

FAILED!

Error Details: {‘code’: -16, ‘message’: ‘Could not authenticate the user’, ‘s’: ‘error’}

Could you please DM me your client ID to get this checked?

the token gets changed at every 30 secs.. so if you get it at 27/28 secs, and by the time you retrieve and send it to authentication URl, it might have expired… if not done already, make some code changes that will wait for few secs before getting TOTP key, if the time is between 25-30secs or 55-60secs

Hi @ankit_prajapati1
We would like to inform you that the authorization token is valid for 5 minutes so it does not expire every 30 seconds during the authentication process.

I have generated auth code 10 to 15 times after that only I am sending this issue and read documents 5 times. The issue comes while generating the Token which is second step. Please check the URL given above which generates auth code and below one for Token. After authcode generation instantly I try to create Token but it fails and gave the auth error. Though I am sending correct authcode,secretid and app id. using this curl curl.exe -X POST “https://api-t1.fyers.in/api/v3/token” -H “Content-Type: application/json” -d ‘{ “grant_type”: “authorization_code”, “appIdHash”: “708f631a17…”, “code”: “eyJhbGc…” }’ Please try this one to generate Token

Hi @111693808730645307047,

There are no issues in generating the auth code. This issue could be from your side, please DM your client ID so we can check it in detail.

Also, please make sure that your APP ID is activated ( by accepting the usage and required permissions). If it’s not activated also, you may get this error.

Regarding the TradingView webhook, you can use FYERS Automate (our new product) to trigger your automation logic via webhooks.

Which client ID Fyers one? How I can DM from here?

I use auth code within 30 seconds to generate the Token

Client ID : FS1974,Well my logic is in Pine script which genrates alert/Trigger .I will check the Fyers one please give me the link .

and I am able to generate AUTH code .Problem is in Token generation. curl.exe -X POST “https://api-t1.fyers.in/api/v3/token” -H “Content-Type: application/json” -d ‘{ “grant_type”: “authorization_code”, “appIdHash”: “708f631a17…”, “code”: “eyJhbGc…” }’ Please try this one to generate Token

Solved was sending wrong Hash code and wrong param name ‘token’ instaed of ‘validate-authcode’ for Tokens genration .Thank you

Solved was sending wrong Hash code and wrong param name ‘token’ instaed of ‘validate-authcode’ for Tokens genration .Thank you

Thank you, Kuber.

We will connect with you.

Here is the link for Fyers Automate: https://fyers.in/web/automate/explore

Thank you, Kuber. Please let us know if you need any further assistance.