Reputation: 491
I have been given the following documentation (https://autovit.zendesk.com/hc/ro/articles/214077685-Obtinere-token-acces) and I want to call this api to get the access token for subsequent requests.
I do not understand how you can multiple parameters
-u 79: 70f8c636a503d50ac6c411597b4cc402
The post request I have been given is: How can we help? dealers partners API Autovit
POST https://ssl.autovit.ro/api/open/oauth/token/
-X POST
-H "Accept: application / json"
-u 79: 70f8c636a503d50ac6c411597b4cc402 [client_id and client_secret]
-d "username = test24 @ test. pl " [username dealer Autovit]
-d" password = 123456789 " [Autovit user password]
-d" grant_type = password "
The code in [ ] are comments by the provider
I will use the request npm module and know that I have to do the following code, but I am not sure how to pass the client_id (in this case 79) and the client_secret, any help would be much appreciated.
request({
url: 'https://ssl.autovit.ro/api/open/oauth/token/',
method: 'POST',
auth: {
user: 'test24 @ test. pl',
pass: '123456789'
},
form: {
'grant_type': 'password'
}
}, function(err, res) {
var json = JSON.parse(res.body);
console.log("Access Token:", json.access_token);
});
Following documentation link I can see that the client id and secret are parameters. So maybe I could use the as the json field1 parameters as below??? :
//Load the request module
var request = require('request');
//Lets configure and request
request({
url: 'https://modulus.io/contact/demo', //URL to hit
qs: {from: 'blog example', time: +new Date()}, //Query string data
method: 'POST',
//Lets post the following key/values as form
json: {
field1: 'data',
field2: 'data'
}
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, body);
}
});
Upvotes: 1
Views: 3188
Reputation: 67
The -u option is for Basic authentication. You can include it in the URL or in the Authorization header as "Basic {auth_hash}".
This article shows each in an example - https://www.haykranen.nl/2011/06/21/basic-http-authentication-in-node-js-using-the-request-module/
Upvotes: 1