Hello Upstox Support Team,
I am encountering a persistent authentication issue with the Sandbox API environment.
Details:
-
API Key: af0ab2a6-a8d4-4984-a24a-cdf5eb057d2c
-
Environment: Sandbox
-
Error Code: UDAPI100050
-
Error Message: Invalid token used to access API
Problem Description:
All of my API calls to any authenticated endpoint are failing with a 401 Unauthorized error, even when using a freshly generated Sandbox access token from the developer dashboard.
Troubleshooting Steps Already Taken:
-
I have revoked my old Sandbox token.
-
I have generated a new Sandbox token multiple times.
-
I have confirmed there are no copy-paste errors.
-
I have tested the new token immediately after generation, and it fails instantly.
-
I have isolated the issue using a minimal Python script, which proves the problem is not with my application’s logic.
Minimal Reproducible Example:
Here is the simple Python script (upstox-python-sdk v2) that consistently reproduces the error:
code Python
downloadcontent_copy
expand_less
import upstox_client
from upstox_client.rest import ApiException
import logging
# This is the newly generated token that is failing.
SANDBOX_ACCESS_TOKEN = "eyJ0eXAiOiJKV1QiLCJrZXlfaWQiOiJza192MS4wIiwiYWxnIjoiSFMyNTYifQ.eyJzdWIiOiI3NjE0MzIiLCJqdGkiOiI2OGFkNTExMWEwMGZmNDE2NWFiMzUxNGEiLCJpc011bHRpQ2xpZW50IjpmYWxzZSwiaXNQbHVzUGxhbiI6dHJ1ZSwiaWF0IjoxNzU2MTg4OTQ1LCJpc3MiOiJ1ZGFwaS1nYXRld2F5LXNlcnZpY2UiLCJleHAiOjE3NTg3NTEyMDB9.eQN_rLb9P5Fvsre0Hj7vinf0RkxbyHRzEzdIUkfLYZc"
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def test_token():
configuration = upstox_client.Configuration()
configuration.access_token = SANDBOX_ACCESS_TOKEN
try:
api_client = upstox_client.ApiClient(configuration)
user_api_instance = upstox_client.UserApi(api_client)
api_response = user_api_instance.get_profile(api_version="v2")
logging.info(f"API Response: {api_response.data}")
except ApiException as e:
logging.error("Authentication Failed.")
logging.error(f"HTTP Status Code: {e.status}")
logging.error(f"Response Body: {e.body}")
if __name__ == "__main__":
test_token()
Full Error Log from the script:
code Code
downloadcontent_copy
expand_less
IGNORE_WHEN_COPYING_START
IGNORE_WHEN_COPYING_END
(venv) PS C:\Users\human\OneDrive\Documents\FACTROID\FEDBKBOT> python .\test_auth.py
2025-08-26 12:27:36,156 - INFO - --- Starting Minimal Authentication Test ---
2025-08-26 12:27:36,547 - ERROR - --- ❌ FAILURE! Authentication Failed. ---
2025-08-26 12:27:36,547 - ERROR - Reason: Unauthorized
2025-08-26 12:27:36,547 - ERROR - HTTP Status Code: 401
2025-08-26 12:27:36,562 - ERROR - Response Body: b'{"status":"error","errors":[{"errorCode":"UDAPI100050","message":"Invalid token used to access API","propertyPath":null,"invalidValue":null,"error_code":"UDAPI100050","property_path":null,"invalid_value":null}]}'
Could you please investigate why my newly generated Sandbox tokens are being rejected as invalid? Please let me know if there is an issue with my application setup or my account.
Thank you for your assistance.
Best regards,
VIJAY