"Google API Message": "This API does not support parsing input formats."

I wrote the following javascript to create a todo list in google:

postData = {'title':'Netsuite List'}; access_token = 'xxxx'; url = 'https://www.googleapis.com/tasks/v1/users/@me/lists'; headers['Content-type'] = 'application/json'; headers['Authorization'] = 'Bearer ' + access_token; headers['Content-length'] = 25; response = $$.requestURL(url, postData, headers, 'POST'); 

The answer says:

 { "error": { "errors": [ { "domain": "global", "reason": "parseError", "message": "This API does not support parsing form-encoded input." } ], "code": 400, "message": "This API does not support parsing form-encoded input." } } 

What is the possible mistake?

+4
source share
2 answers

You have sent data such as:

 title=Netsuite%20List 

But the Google API is waiting for JSON :

 { "title": "Netsuite List" } 

Try providing JSON.stringify() output in the requestURL method:

 postData = JSON.stringify({'title':'Netsuite List'}); // <-- Added JSON.stringify access_token = 'xxxx'; url = 'https://www.googleapis.com/tasks/v1/users/@me/lists'; headers['Content-type'] = 'application/json'; headers['Authorization'] = 'Bearer ' + access_token; headers['Content-length'] = 25; response = $$.requestURL(url, postData, headers, 'POST'); 

Also, it’s best to go around the documentation or source of the $$ object you are using and see how it can support sending JSON data.

0
source

does not work

 contentType: 'application/json; charset=UTF-8', 

try with this

 var headers = { }; headers["Content-Type"] ="application/json ; charset=UTF-8"; //remove to parsing form-encoded input error data:JSON.stringify( model), //this use for remove to parse error 

Example:

 $.ajax({ type: 'Post', url: postUrl, headers: headers, dataType: 'json',//not required in some case data:JSON.stringify( model), success: function (data, sts) { alert('success'); }, error: function (err, sts) { var msg; } }); 
0
source

Source: https://habr.com/ru/post/1487618/


All Articles