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.
Related
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"}
};
I am trying to create a fetch call to servicedesk plus system but I keep getting 400 error, I understand that the request I made is not what the server wanted but in postman, I do manage to send that same query successfully. I can't understand what is the problem
In the dev tools network tab I see this data after dending the Json:
response_status: {status_code: 4000,…}
messages: [{status_code: 4001, field: "input_data", type: "failed", message: "JSON cant be analyzed"}]
0: {status_code: 4001, field: "input_data", type: "failed", message: "JSON cant be analyzed"}
field: "input_data"
message: "JSON cant be analyzed"
status_code: 4001
type: "failed"
status: "failed"
status_code: 4000
From what I read in the API documentation I saw that the 4001 error means that the ID or the name are not as they are in the service desk system.
here is a link to the API docs
this is my code:
const jss = {
"request": {
"subject": "test 29072020",
"description": "TEST REQUEST BY DAVID",
"requester": {
"id": "1231",
"name": "david"
},
"resolution": {
"content": "Mail Fetching Server problem has been fixed"
},
"status": {
"name": "פתוחה"
},
"template": {
"name": "Test for API",
"id": "123123"
},
}
}
const sendToSd = document.getElementById('send');
sendToSd.addEventListener('click', submitData);
var mydata = JSON.parse(jss);
var stringify = JSON.stringify(mydata);
async function submitData(){
const url = 'http://MYURL.COM/api/v3/requests?TECHNICIAN_KEY=SOME-STRING&input_data='+stringify+'&FORMAT=json';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
console.log('response',response)
}
This fetch works and manages to retrieve the data from the service desk using the same URL and TECHNICIAN_KEY.
// fetch('http://MYURL.COM/api/v3/requests/61627?TECHNICIAN_KEY=SOME-STRING', {
// method: 'GET'
// })
// .then(response => {
// console.log(response);
// return response;
// });
I am trying to get the current user from https://graph.microsoft.com/v1.0/me.
I get a valid token, however, the request to https://graph.microsoft.com/v1.0/me gives me a 404.
var token;
$(document).ready(function () {
requestToken();
});
function requestToken() {
$.ajax({
"async": true,
"crossDomain": true,
"url": "https://cors-anywhere.herokuapp.com/https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"grant_type": "client_credentials",
"client_id ": "{client_id}",
"client_secret": "{client_secret}",
"scope ": "https://graph.microsoft.com/.default"
},
success: function (response) {
console.log(response);
token = response.access_token;
getUserInformation();
},
error: function (error) {
console.log(JSON.stringify(error));
}
})
}
function getUserInformation() {
$.ajax({
method: 'GET',
url: "https://graph.microsoft.com/v1.0/me",
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
},
}).success(function(response) {
console.log(response);
}).error(function(error) {});
}
Anyone knows what might be the problem?
Thank you.
I got a detailed response:
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"request-id": "",
"date": "2020-04-17T09:33:43"
}
}
}
from https://graph.microsoft.com/v1.0/me
I got:
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token is empty.",
"innerError": {
"date": "2020-10-20T11:39:50",
"request-id": "becb1443-91e3-42d9-9c77-b9808aaf2cf7",
"client-request-id": "becb1443-91e3-42d9-9c77-b9808aaf2cf7"
}
}
}
https://graph.microsoft.com/.default
{
"error": {
"code": "BadRequest",
"message": "Invalid version.",
"innerError": {
"date": "2020-10-20T11:41:04",
"request-id": "3fdd24bd-7c96-4ff2-9e18-fc042673ecd2",
"client-request-id": "3fdd24bd-7c96-4ff2-9e18-fc042673ecd2"
}
}
}
Usually, request returns 404 status code when the route does not exist, So I'll recommend you to please check the provided URI is valid or not.
Im trying to send a request to a rest API and granted my knowledge using jquery is not advance however through numerous tutorials I'm struggling a bit to build a request based on this swagger documentation.
{
"fields": {
"": [
{
"NAME": "NAME"
},
{
"ADDRESS": "ADDRESS"
},
{
"EMAIL": "EMAIL"
}
]
}
}
This is the model of how i need to send the Rest request, im able to do this using postman however i struggle to do this in javascript.
var data = {};
var json = [{ "NAME": "name", "ADDRESS": "address", "EMAIL": "email" }];
data.fields ={json};
My problem is that in the model there is an empty quotation which im unable to replicate. I suspect that either the rest API is not the best or im missing something quite vital in building a request. See below for the actual ajax jquery request.
var request = $.ajax({
type: "POST",
url: urlBase,
contentType: 'application/json',
data: JSON.stringify({json}),
});
request.done(function (msg) {
alert(msg);
$("#log").html(msg);
});
request.fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
}
Error message based on the above request
Invalid field groups: [json] used in the search fields not found in duplicate store schema
You can create a json like this:
var obj = {
"": [{
"NAME": "NAME"
},
{
"ADDRESS": "ADDRESS"
},
{
"EMAIL": "EMAIL"
}
]
}
console.log(obj)
Hope it helps. Revert for any doubts.
I'm building a mobile client to talk to a bot built with microsoft botbuilder through botconnector directline. I want to send things like the unique id of the user speaking with the bot, so my bot can operate on this user. Currently I'm just POSTing to directline, but when I add additional things in the body, my bot can't retrieve it. I'm probably doing something really simple wrong. Would love to get your help on this!
POST code from client:
sendToBot: function(setUpObj, message, returnCallback){
var postURL=baseURL+"/"+setUpObj.conversationId+"/messages"
var postOptions ={
method: 'POST',
headers: {
"Authorization": setUpObj.conversationToken,
"content-type": "application/json"
},
body: JSON.stringify({
"text": message,
"from": {
'address': setUpObj.currentUserUid
}
})
}
fetch(postURL, postOptions)
.then(
(response)=>response.text()
)
.then(
(responseText)=>{
this.getResponse(setUpObj, returnCallback)
}
)
}
and I'm accessing the the currentUserUid on the server by
session.message.from.address
Thanks for you patience.
Have you tried setting the channelData in the json? It's described as "data sent unmodified between client and bot" and can look like:
{
"id": "CuvLPID4kDb|000000000000000004",
"conversationId": "CuvLPID4kDb",
"created": "2017-02-22T21:19:51.0357965Z",
"from": "examplebot",
"text": "Hello!",
"channelData": {
"examplefield": "abc123"
}
}
https://docs.botframework.com/en-us/core-concepts/channeldata/
So in your code it could look like:
var postOptions ={
method: 'POST',
headers: {
"Authorization": setUpObj.conversationToken,
"content-type": "application/json"
},
body: JSON.stringify({
"text": message,
"channelData": {
"from": {
"address": setUpObj.currentUserUid
}
}
})
}