Need the code generate authorization code having apikey and secret

I am new to upstox api. i had created an app. and got the api key, secret. redirect url i have as https://localhost

please give me full code in python to generate auth code for api v2

Durga Prasad

Hello @Durga_Prasad,
Upstox API does not support or recommend automating login or access token generation in light of SEBI and regulatory guidelines. Users are required to log in manually once daily by adhering to the specified login procedures. To generated auth_code please refer API Documentation | Authentication

After generation auth code please follow this.
Be rest assured that the provided code below has been tested and matches the code found in the Example Codes - Login section.

import requests

url = 'https://api.upstox.com/v2/login/authorization/token'
headers = {
    'accept': 'application/json',
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
    'code': '{your_code}',
    'client_id': '{your_client_id}',
    'client_secret': '{your_client_secret}',
    'redirect_uri': '{your_redirect_url}',
    'grant_type': 'authorization_code',
}

response = requests.post(url, headers=headers, data=data)

print(response.status_code)
print(response.json())

Please verify that you are using the correct values in the opts object:

  • Refer to the API Documentation for code generation.
  • Note that clientId and clientSecret refer to your API Key and API Secret respectively, which are associated with your app. You can find them under My Account -> App -> My Apps -> Your App Name.
  • Ensure that redirectUri matches the redirect URI you specified during app creation.

For detailed instructions on creating an Upstox API app, see How to create an API app. Additionally, explore the API Documentation for a deeper understanding of the Upstox API.