API access issue

Dear Team Fyers,

I have been working on algo trading using Python for the past 1.5 years with my primary account. Recently, I tried to enable API access for another Fyers account, but I’m facing an error during the token generation process.


Code used to generate Token:
def generate_auth_code(): # Step 1 - Retrieve request_key from send_login_otp API send_otp_result = send_login_otp(fy_id=FY_ID, app_id=APP_ID_TYPE) if send_otp_result[0] != SUCCESS: print(f"send_login_otp failure - {send_otp_result[1]}") sys.exit() else: print("send_login_otp success") # Step 2 - Generate totp generate_totp_result = generate_totp(secret=TOTP_KEY) if generate_totp_result[0] != SUCCESS: print(f"generate_totp failure - {generate_totp_result[1]}") sys.exit() else: print("generate_totp success") # Step 3 - Verify totp and get request key from verify_otp API request_key = send_otp_result[1] totp = generate_totp_result[1] verify_totp_result = verify_totp(request_key=request_key, totp=totp) if verify_totp_result[0] != SUCCESS: print(f"verify_totp_result failure - {verify_totp_result[1]}") sys.exit() else: print("verify_totp_result success") # Step 4 - Verify pin and send back access token request_key_2 = verify_totp_result[1] verify_pin_result = verify_PIN(request_key=request_key_2, pin=PIN) print("\nverify_pin_result_0:", verify_pin_result[0]) print("\nverify_pin_result_1:", verify_pin_result[1]) if verify_pin_result[0] != SUCCESS: print(f"verify_pin_result failure - {verify_pin_result[1]}") sys.exit() else: print("verify_pin_result success") # Step 5 - Get auth code for API V2 App from trade access token token_result = token( fy_id=FY_ID, app_id=APP_ID, redirect_uri=REDIRECT_URI, app_type=APP_TYPE, access_token=verify_pin_result[1] ) print("\ntoken_result:", token_result[0]) print("\ntoken_result:", token_result[1]) if token_result[0] != SUCCESS: print(f"token_result failure - {token_result[1]}") sys.exit() else: print("token_result success") # Step 6 - Get API V2 access token from validating auth code auth_code = token_result[1] print("auth_code:", auth_code) return auth_code

The strange thing is that the same code works perfectly with my primary account, but when I use it with another account, it throws the following error:

token_result failure - {"code":"","data":{"appName":"AlgoTrading","app_id":"xxx","auth":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJbXCJkOjFcIixcImQ6MlwiLFwieDowXCIsXCJ4OjFcIixcIng6MlwiXSIsImF0X2hhc2giOiJnQUFBQUFCbzR6LVVKNTVYZjlpNHpfeEJpNmtqdWU1aHlOYzUwMHNzRUJwdDBKdUFIa3JNR1B5dXJrR2RqS1BGWUp3OGtsbUlMei1GSHVhZ1ZyNTRVc2RrWVNFbWpRYlRVUmc1a1dtcVpBdlZkVVFONktIY1Ffdz0iLCJkaXNwbGF5X25UiOiJGQUM4NzE2NCIsIm9tcyI6IksxIiwiaHNtX2tleSI6ImRmNjJjOGIyYjYxNjk1OGRlY2I0Y2RlNzdjOWRiMzFmY2M0MjEzM2UzYWFiMTk5NzM1YmYyZjk1IiwiaXNEZHBpRW5hYmxlZCI6Ik4iLCJpc010ZkVuYWJsZWQiOiJOIiwiZXhwIjoxNzU5NzIzNzEyLCJpYXQiOjE3NTk3MjM0MTIsImlzcyI6ImFwaS5meWVycy5pbiIsIm5iZiI6MTc1OTcyMzQxMiwic3ViIjoiYWNjZXNzX3Rva2VuIn0.9hSWXd2f2s35En-bXmEmGBAlC_4UOZykTiIgd7ijm8g","image":"None","nonce":"","permissions":["d:1","d:2","x:0","x:1","x:2"],"redirectUrl":"https://www.google.com","response_type":"code","scope":"","state":"sample_state","user_id":"xxx"},"message":"","s":"ok"}

1 reply