const headers = {
Authorization: 'Bearer fui3h73bjflkbf-hdug37o8'
}
const body = { "name": "example.com", "account": { "id": "72672yhhuo2nu2" }, "jump_start": true, "type": "full" }
let url = 'https://api.cloudflare.com/client/v4/zones'
axios.post(
url,
body,
headers
).then(console.log).catch(console.log);
Can any help me with this? I keep getting a 400 bad request from Axios - I can pass that same token over a GET request and confirm its working fine
What do you use to check the response? Here is the body of request:
{
"success": false,
"errors": [
{
"code": 6003,
"message": "Invalid request headers",
"error_chain": [
{
"code": 6111,
"message": "Invalid format for Authorization header"
}
]
}
],
"messages": [],
"result": null
}
So the problem is that you send wrong token. Check if it is correct.
You may use this one "Bearer YQSn-xWAQiiEh9qM58wZNnyQS7FUdoqGIUAbrh7T" from cloudflare site to check if you will get 403 Forbidden instead of your current 400. If so, your request is fine, and you just need correct token.
It was formatting
var config = {
headers: {'Authorization': "Bearer fui3h73bjflkbf-hdug37o8"}
};
Related
I am trying to integrate https://www.checkout.com/ in my app.
I tried there sample code to get token.
Frames.addEventHandler(
Frames.Events.CARD_TOKENIZED,
function (data) {
Frames.addCardToken(form, data.token);
if (data.token) {
confirmPayment(data.token);
} else {
console.log(data);
}
}
);
I tried https://api.sandbox.checkout.com/payments/ api to do the payments,
payment successfully captures, but I am unable to read its response to or redirect user on successfully attempt.
async function confirmPayment(token) {
// Storing response
const response = await fetch('https://api.sandbox.checkout.com/payments/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk_sbox_..abc'
},
body: JSON.stringify({
"source": {
"type": "token",
"token": token
},
"Capture": true,
"processing_channel_id": "pc_..abc",
'amount': 1000,
'currency': 'USD',
"3ds": {
"enabled": false
},
"customer": {
"email": "test.testUI#example.com",
"name": "John Test"
},
'reference': 'ORD-175-759',
"metadata": {
"udf1": "UI-CALL-TEST",
"coupon_code": "NY2018",
"partner_id": 123989
},
"success_url": "http://example.com/payments/success",
"failure_url": "http://example.com/payments/fail"
})
});
// Storing data in form of JSON
var data = await response.json();
console.log(data);
if (response) {
}
show(data);
}
I want to get a payment response like errors "card invalid" etc
Also redirect to Url if successful.
Please let me know if this is a correct way to do the payment or If there any JavaScript library that I can use?
I want to do payment on client side and use webhook later.
Thank you
I have some issues with an API with oauth2 authentication.
After I get the token, and I want to sent my POST request but it still gives me a 415 error (Unsupported Media Type). I'm sure my payload's fields are good because I tried with postman and it works, but I don't know if I have to JSON stringify the header (the payload I think, but I'm not sure at 100%). I run my code on Google apps script so I thought the problem came from apps script, but I can get the token and send GET request on it.
function post_pers() {
var url = "(my url)";
var data = {
"id": 32,
"nom": "apij",
"prenom": "joseph",
"civiliteLongue": "Monsieur",
"idTypePersonne": "PERSTPHYSIQUE ",
"ligne1Adresse": " ",
"ligne2Adresse": " ",
"ligne3Adresse": " ",
"codePostal": " ",
"commune": " ",
"idPays": "FR",
"iban": " ",
"bic": " ",
"titulaireCompte": " ",
"domiciliationBanque": " ",
"assujettiTva": true,
"mediaPrefere": "Mail",
}
var payload = JSON.stringify(data);
Logger.log("payload; "+payload)
Logger.log("data; "+data)
var header1 = {
"accept": "application/json",
"authorization": "Bearer (my access token)",
"content-type": "application/json"
}
var header = JSON.stringify(header1);
Logger.log("header; "+header)
Logger.log("header1; "+header1)
var options = {
"method": "POST",
"header": header,
"payload": payload
}
var response = UrlFetchApp.fetch(url, options);
Logger.log(response)
}
415 is unsupported media. This is usually due to Content-Type header typos. Your script is stringifying headers, which would make header unreadable by the server. Try
var options = {
"method": "POST",
"header": /*header*/header1,
"payload": payload
}
I am new to Jira API & I am currently creating a google form to create a subtask automatically for any ad-hoc requests attaching to an existing story that is already created manually.
URL: https://<subdomain>.atlassian.net/jira/software/c/projects/<PROJECTID>
STORY CREATED: PROJECTID-XXX
I have the following sample code to test:
function createSubTask(summary, description) {
var URL = 'https://<subdomain>.atlassian.net/rest/api/3/issue';
var username = '<user-name>';
var password = '<api-key>';
var userCreds = "Basic " + Utilities.base64Encode(username + ':' + password);
var data = {
"project": {"key": "PROJECTID"},
"parent": {"key": "PROJECTID-XXX"},
"summary": summary,
"description": description,
"issuetype": {"name":"Sub-task"}
};
var payload = JSON.stringify(data);
var headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": userCreds,
"muteHttpExceptions": "True"
};
var options = {
"method": "POST",
"headers": headers,
"payload": payload
}
var response = UrlFetchApp.fetch(URL, options);
Logger.log(response);
}
I am getting the following error:
Exception: Request failed for https://<subdomain>.atlassian.net returned code 400. Truncated server response: {"errorMessages":[],"errors":{"project":"Specify a valid project ID or key"}} (use muteHttpExceptions option to examine full response)
Not sure, what I am doing wrong.
"muteHttpExceptions": true
muteHttpExceptions be in the options block and true should be a bool not a string.
I was getting the Specify a valid project ID or key error, then swapped this in the options block and got a response error that was actually the problem.
Use the following payload format. It will fix the problem.
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
I am making an application that sends emails from a User as described by this article.
Everything is working as expected, except for when I try to include an attachment. The email sends, but without the attachment. I'm not sure what the problem is as I've tried pretty much everything I could find online. I have made sure the file I am sending is properly encoded in base64.
var message = {
"subject": subject,
"hasAttachments":true,
"body": {
"contentType": "Text",
"content": emailBody
},
"toRecipients": toRecipients,
ccRecipients,
bccRecipients
};
function sendMailRequest(access_token, message, uriSend, file, base64, callback){
const attachments = [{
'#odata.type': '#microsoft.graph.fileAttachment',
"contentBytes": base64
"name": "example.jpg"
}];
// Configure the request
var options2 = {
"url": uriSend,
"method": 'POST',
"headers": {
'Authorization': access_token,
'Content-Type': 'application/json'
},
"body": JSON.stringify({
"message": message,
"SaveToSentItems": "true",
"Attachments": attachments
})
}
Attachments go inside the message JSON, not outside of it. This should work:
function sendMailRequest(access_token, message, uriSend, file, base64, callback) {
const attachments = [
{
"#odata.type": "#microsoft.graph.fileAttachment",
"contentBytes": base64
"name": "example.jpg"
}
];
message["attachments"] = attachments;
// Configure the request
var options2 = {
"url": uriSend,
"method": "POST",
"headers": {
"Authorization": access_token,
"Content-Type": "application/json"
},
"body": JSON.stringify({
"message": message,
"SaveToSentItems": "true"
})
}
...
}
I'm trying to implement a simple POST call in meteor.js to the Google Calendar API, and I'm stuck. My request looks like this:
var id = Meteor.http.post("https://www.googleapis.com/calendar/v3/calendars/", {
'headers' : {
'Authorization': auth, // auth = "Bearer " + Meteor.user().services.google.accessToken
'Content-Type': 'application/json'
},
'parameters': {},
'body' : {
'title': "Calendar Title",
}
});
and I get the following error:
Error: failed [400] {
"error": {
"errors": [{
"domain": "global",
"reason": "required",
"message": "Missing title."
}],
"code": 400,
"message": "Missing title."
}
}
Any ideas?
Solved it. This is dumb.
Take out parameters, and make "body" "data" instead and it works.