I did…
import requests
Upstox API details
payload = {
‘client_id’: ‘YOUR_CLIENT_ID’, # Replace with your client ID
‘redirect_uri’: ‘YOUR_REDIRECT_URI’, # Replace with your redirect URI
‘response_type’: ‘code’
}
headers = {
‘accept’: ‘application/json’,
‘Api-Version’: ‘2.0’,
‘Content-Type’: ‘application/x-www-form-urlencoded’
}
url = “https://login.upstox.c … .etc / v2/ oauth/ authorize”
response = requests.get(url, headers=headers, params=payload)
Print the URL to visit for authorization
print(response.url)
Upstox API endpoint for token exchange
token_url = "https: //api-v2.upstox.c…,etc etc /authorization/token "
Replace with the actual authorization code you received
authorization_code = ‘YOUR_AUTHORIZATION_CODE’
Payload for the token exchange request
payload_token = {
‘code’: authorization_code,
‘client_id’: ‘YOUR_CLIENT_ID’, # Replace with your client ID
‘client_secret’: ‘YOUR_CLIENT_SECRET’, # Replace with your client secret
‘redirect_uri’: ‘YOUR_REDIRECT_URI’, # Replace with your redirect URI
‘grant_type’: ‘authorization_code’
}
Headers for the request
headers_token = {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
‘Accept’: ‘application/json’
}
Send the POST request to exchange the authorization code for an access token
response_token = requests.post(token_url, headers=headers_token, data=payload_token)
Handle the response
if response_token.status_code == 200:
access_token_data = response_token.json()
print(“Access Token:”, access_token_data[‘access_token’])
else:
print(“Failed to get access token:”, response_token.text)
And as Output I got the “URL”(which is working fine) and "Failed to get access token: “This API is deprecated, please migrate to Upstox API v2. For more details refer upstox documentation”