Access Token Request for User
Access token request
- Curl
- Python
- Node.js
- Java
- PHP
- Python SDK
- Node.js SDK
- Java SDK
curl -X 'POST' 'https://api.upstox.com/v3/login/auth/token/request/678d46e1-91ac-4b8d-925d-89c8e3015c2b' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"client_secret": "{your_client_secret}"
}'
import requests
url = 'https://api.upstox.com/v3/login/auth/token/request/678d46e1-91ac-4b8d-925d-89c8e3015c2b'
headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
}
data = {
'client_secret': '{your_client_secret}'
}
response = requests.post(url, headers=headers, data=data)
print(response.status_code)
print(response.json())
const axios = require('axios');
const url = 'https://api.upstox.com/v3/login/auth/token/request/678d46e1-91ac-4b8d-925d-89c8e3015c2b';
const headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
};
const data = {
'client_secret': '{your_client_secret}'
};
axios.post(url, new URLSearchParams(data), { headers })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error(error.response.status);
console.error(error.response.data);
});
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) throws Exception {
String apiUrl = "https://api.upstox.com/v3/login/auth/token/request/678d46e1-91ac-4b8d-925d-89c8e3015c2b";
HttpURLConnection con = (HttpURLConnection) new java.net.URL(apiUrl).openConnection();
// Set the request method
con.setRequestMethod("POST");
// Set the request headers
con.setRequestProperty("accept", "application/json");
con.setRequestProperty("Content-Type", "application/json");
// Enable input/output streams
con.setDoOutput(true);
// Set the request data
String data = "{"
+ "\"client_secret\": \"{your_client_secret}\""
+ "}";
// Write the request data to the output stream
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
wr.write(data.getBytes(StandardCharsets.UTF_8));
wr.flush();
}
// Get the response code
int responseCode = con.getResponseCode();
System.out.println("Response Code: " + responseCode);
// Read the response
try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
// Print the response
System.out.println(response.toString());
}
}
}
<?php
$url = 'https://api.upstox.com/v3/login/auth/token/request/678d46e1-91ac-4b8d-925d-89c8e3015c2b';
$headers = [
'accept: application/json',
'Content-Type: application/json',
];
$data = [
'client_secret' => '{your_client_secret}'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Response Code: $httpCode\n";
echo "Response Data: $response\n";
?>
import upstox_client
from upstox_client.rest import ApiException
configuration = upstox_client.Configuration()
api_instance = upstox_client.LoginApi(upstox_client.ApiClient(configuration))
body = upstox_client.IndieUserTokenRequest(client_secret="****")
try:
api_response = api_instance.init_token_request_for_indie_user(body,client_id="*****")
print(api_response)
except ApiException as e:
print("Exception when calling indie token request: %s\n" % e)
let UpstoxClient = require('upstox-js-sdk');
let apiInstance = new UpstoxClient.LoginApi();
let body = new UpstoxClient.IndieUserTokenRequest();
body.clientSecret = "your_client_secret"; // Replace with your actual client secret
apiInstance.initTokenRequestForIndieUser(body,"your_client_id", (error, data, response) => {
if (error) {
console.error(error.response.text);
} else {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}
});
import com.upstox.ApiException;
import com.upstox.api.IndieUserInitTokenResponse;
import com.upstox.api.IndieUserTokenRequest;
import io.swagger.client.api.LoginApi;
public class Main {
public static void main(String[] args) {
LoginApi loginApi = new LoginApi();
IndieUserTokenRequest indieUserTokenRequest = new IndieUserTokenRequest();
indieUserTokenRequest.setClientSecret("your_client_secret");
try {
IndieUserInitTokenResponse indieUserInitTokenResponse = loginApi.initTokenRequestForIndieUser(indieUserTokenRequest, "your_client_id");
System.out.println(indieUserInitTokenResponse);
} catch (ApiException e) {
System.out.println(e.getResponseBody());
throw new RuntimeException(e);
}
}
}