Access tokens are the thing that applications use to make API requests on behalf of a user. The access token represents the authorization of a specific application to access specific parts of a user’s data.
We can execute below command for obtaining Oauth2 access token
UAT Token endpoint : https://partnersuat.oxymoney.com/authserver/oauth/token
PROD Token endpoint : https://partners.oxymoney.com/authserver/oauth/token
curl -u [client_id]:[password] -d "username=[agent_id]&password=[agent_password]&grant_type=password" -H "Content-Type: application/x-www-form-urlencoded" -X POST [token enpoint]
C#
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "[Token Endpoint]"))
{
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("[client_id]:[password]"));
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
request.Content = new StringContent("username=[agent_id]&password=[agent_password]&grant_type=password");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
var response = await httpClient.SendAsync(request);
}
}
PHP
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '[Token Endpoint]');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=[agent_id]&password=[agent_password]&grant_type=password");
curl_setopt($ch, CURLOPT_USERPWD, '[client_id]' . ':' . '[password]');
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
NodeJS
var request = require('request');
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var dataString = 'username=[agent_id]&password=[agent_password]&grant_type=password';
var options = {
url: '[Token Endpoint]',
method: 'POST',
headers: headers,
body: dataString,
auth: {
'user': '[client_id]',
'pass': '[password]'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
Open https://api.oxymoney.com/swagger-ui.html on your browser