I am trying to download a File from dropbox using Dropbox APIs. I use the code below
axios.post('https://content.dropboxapi.com/2/files/download', {
method: 'POST',
headers: {
Authorization: 'Bearer ${MY token}',
'Dropbox-API-Arg': { path: '/Thillai Maharajan.jpg' }
}
})
.then(function (response) {
console.log("RESPONSE: ",response.data);
})
.catch(function (error) {
console.log("ERROR RES",error);
});
But it says data: 'Error in call to API function "files/download": Must provide HTTP header "Authorization" or URL parameter "authorization".'
Can anyone help?
You can refer the Dropbox API Document at https://www.dropbox.com/developers/documentation/http/documentation#files-download
I just got the answer. I have to Stringify the Dropbox-API-Arg Parameter using JSON.stringify(). Because The header argument could not be a JSON. I changed that and it worked.
'Dropbox-API-Arg' : JSON.stringify({"path":"/Thillai Maharajan.jpg"})
Related
I am implementing recaptcha into a user submittable form. After attempting to validate the token using the url
https://www.google.com/recaptcha/api/siteverify
The response given is something similar to
▼���RPP*.MNN-.V�RHK�)N�☺��▬§�↨�&秤�ģ�B#�̼�Ĝ�¶�̼��↕ݢ�����T%�d,W-�
� K
The code used to attempt to validate the response is as follows
var data = JSON.stringify({
secret: process.env.RECAPTCHA_SECRET,
response: req.body.gcaptcha_response,
});
var config = {
method: "post",
url: "https://www.google.com/recaptcha/api/siteverify",
headers: {
"Content-Type": "application/json",
},
data: data,
};
axios(config)
.then(function (response) {
res.json({
success: true,
body: response.data,
});
})
.catch(function (error) {
console.log(error);
});
I have also attempted with other content types to no success. I have also attempted to follow the answer given in this thread
This is a workaround for now
I just realised this is happening for the latest version of axios.
If you install axios version 1.1 it returns the data as json.
Thread: https://github.com/axios/axios/issues/5298
I recently found out that request is no longer maintained, so the best alternative I found is got. I am trying to make an external API call to a REST Server but I am unsure as to how I can add a Bearer token in the authorization header of the POST request.
This is my code:
const response = await got.post(
"https://${SERVER}/${SOME_ID}/conversations/${CONVERSATION_ID}/messages",
{
json: [
{
text: req.body.message,
type: "SystemMessage",
}
],
responseType: "json",
headers: {
token: "Bearer pXw4BpO95OOsZiDQS7mQvOjs"
}
}
);
This results in a 401 Unauthorized. I was unable to find direction to such implementation in the documentation provided by GOT. And since there are not a lot of queries regarding this package, I was unsuccessful in finding anything on Google as well. If anyone can help me out in this regard, that would be very helpful!
Are you sure that the header name is "token" ?
Usually in API, the Bearer is in a header called "Authorization"
const response = await got.post(
"https://${SERVER}/${SOME_ID}/conversations/${CONVERSATION_ID}/messages",
{
json: [
{
text: req.body.message,
type: "SystemMessage",
}
],
responseType: "json",
headers: {
"Authorization": "Bearer pXw4BpO95OOsZiDQS7mQvOjs"
}
}
);
Here is the code
npm i postman-request link for npm package
const request = require('postman-request');
request({
url: 'your url',
headers: {
'Authorization': 'Bearer 71D50F9987529'
},
rejectUnauthorized: false
}, function(err, res) {
if(err) {
console.error(err);
} else {
console.log(res.body);
}
});
I set up my express app to listen for Paypal webhooks of my sandbox app. Then I try to verify the integrity of the data via the verify-webhook-signature API endpoint. I use the request module for that. But all I get is a 415 Unsupported Media Type status code and an empty body. This is my code:
app.post('/webhooks', function (req, res) {
if (req.body.event_type == 'PAYMENT.CAPTURE.COMPLETED') {
headers = {
'Accept' : 'application/json',
'Content-Type' : 'application/json',
'Authorization' : 'Bearer <AUTH_TOKEN>'
}
// Get the data for the API call of the webhook request
data = {
'transmission_id': req.headers['paypal-transmission-id'],
'transmission_time': req.headers['paypal-transmission-time'],
'cert_url': req.headers['paypal-cert-url'],
'auth_algo': req.headers['paypal-auth-algo'],
'transmission_sig': req.headers['paypal-transmission-sig'],
'webhook_id': '41G05244UL253035G',
'webhook_event' : req.body
}
request.post({
url: 'https://api.sandbox.paypal.com/v1/notifications/verify-webhook-signature',
headers: headers,
form: data,
}, (error, response, body) => {
if (error) {
console.error(error)
return
}
console.log(response.statusCode);
});
}
res.sendStatus(200);
});
What is wrong with this data?
Edit: Changing 'form: data' to 'body: JSON.stringify(data)' did it.
Why are you sending back a form post? Don't post a form. Send back raw data.
I am learning Node by developing an application that would hit the relevant server and extract its data.
Here, I am stuck as the relevant server demand to pass access token, and I'm not able to extract data successfully.
Here is my code
var options = {
method: 'GET',
url: 'any url',
auth : {
accessToken : "token here"
},
headers: {
'Accept': 'application/json'
}
}
But doing this i'm getting error Error: no auth mechanism defined
Access token seems to be perfect.
Sorry if this has been asked already but I cannot seem to find a straight answer.
Thanks for your efforts and time.
Try this :
var req = {
host: 'YOUR_URL',
method: 'GET',
headers: {
Authorization: your token
'Content-Type': 'application/json'
}
}
request(req, function(error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body);
}
I am trying to call external API using Node and AngularJS as a front end. My requirement is to pass Etag header parameter through put request to external API. I am not able to pass Etag parameter from headers. Can anyone tell me how to do that?
I have tried below code to pass through put request but still I have not reached a solution.
'If-Match': function(config) {
return config.data.version;
}
Node API:
router.put('/node1Api', function(req, res){
request.put(
{
url:'Example.com',
json: {
"caseTypeID": "EAIS-UCEF-Work-ComplaintProcess",
"content": {
"ComplaintReason" : req.body.ComplaintReason,
"ComplaintDescription" : req.body.ComplaintDescription,
}
},
headers: {
'Content-Type': 'application/json',
'If-Match': function(config) {
return config.data.version;
}
}
},
function(error, response, body){
console.log(body);
res.send(body);
})
});
I want to pass that If-Match Tag as a header parameter. I want to match this Etag (If-Match) header parameter with external API so that we get success response and our details get updated in that subsequent case.