Access Token Request for User
Access token request
- Curl
- Python
- Node.js
- Java
- PHP
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";
?>