Microsoft Graph API One Drive Unable to read JSON request payload - onedrive

I receive the following error when I make an PUT API CALL to upload a document to OneDrive using Microsoft Graph API. It was working earlier, it has stopped working suddenly.
{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n
\"message\": \"Unable to read JSON request payload. Please ensure
Content-Type header is set and payload is of valid JSON format.\",\r\n
\"innerError\": {\r\n \"request-id\":
\"133ac360-740d-4823-9a93-1090616d925b\",\r\n \"date\":
\"2016-04-11T06:24:59\"\r\n }\r\n }\r\n}
The code which I am executing is
using (var client = new HttpClient())
{
string url = https://graph.microsoft.com/v1.0/me/drive/root:/Test.xslx:/content
using (var request = new HttpRequestMessage(HttpMethod.Put, url))
{
string headerAcceptTest = "application/json";
MediaTypeWithQualityHeaderValue headerAccept = new MediaTypeWithQualityHeaderValue(headerAcceptTest);
request.Headers.Accept.Add(headerAccept);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
request.Content = new ByteArrayContent(data);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
using (var response = await client.SendAsync(request))
{
if (response.StatusCode == HttpStatusCode.Created)
{
string responseContentAsString = await response.Content.ReadAsStringAsync();
}
}
}
}
Any clue where am I going wrong?

There was an issue with a new build that was rolled out over the weekend, and we have now reverted it. The issue should now be resolved.

I saw a change in behavior of the One Drive API on uploading a file to One Drive.( https://dev.onedrive.com/items/upload_put.htm) , this API call fails with error.
Sample Request :
PUT https://graph.microsoft.com/v1.0/me/drive/items/root/children/732f64cc-0719-4a24-abe8-6fd39cb96403.txt/content?%40name.conflictBehavior=replace
Response
{
"error": {
"code": "BadRequest",
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
"innerError": {
"request-id": "7e734f93-3033-4bb4-a433-c5d9c400f46e",
"date": "2016-04-11T02:33:35"
}
}
}
Actually it was working fine until 8th April 2016, The Documentation says its text/plain content type , why is this expecting application/json

Related

does the data sent to the server using http Post update the servers API url?

Im a newbie to flutter so please if you think the question context is wrong update it, im fetching a data from an SQl server to my flutter app, and i also want to send the users info back to the server after they fill out a form, im using the http.post and i get the response’s body correctly but when i open the Server Url (api url) i dont see it updated with the new info i posted to it, can someone please tell me how Post is supposed to work?
I'm new to Flutter too, this is a working example of how i understand it
class HttpService {
createUser(String name, String lastname) async {
Map data = {'name': name, 'lastname': lastname};
var body = json.encode(data);
var jsonResponse = null;
var response = await http.post(serverUrl + "/create/",
headers: {
HttpHeaders.authorizationHeader: '**Token_here_if_you_use_it**',
HttpHeaders.contentTypeHeader: "application/json",
}, body: body);
jsonResponse = json.decode(response.body);
if (response.statusCode == 201) {
jsonResponse = json.decode(response.body);
if (jsonResponse != null) {
print(jsonResponse.toString());
}
} else {
print(jsonResponse.toString());
}
}
}
In your main.dart :
final HttpService httpService = HttpService();
httpService.createUser(name,lastname);

Imgur can't upload "message": "Failed stripping metadata"

I'm making an api getting a gif that uploads it to imgur,
but when requesting the api (express or postman),
i receive an error (everything works fine with other pictures):
{
data: {
error: {
code: 1001,
message: "Failed stripping metadata",
type: "Exception_Logged",
exception: {}
},
request: "/3/upload",
method: "POST"
},
success: false,
status: 500
}
How to avoid this error ? How to correct this picture ? "Adding metadata ?"
Is it due to the fact the picture was saved with ffmpeg ?
When i upload with the imgur pannel, everyting is fine,but not with the api
Thanks
https://imgur.com/xn4iG08
Note: i suppose the medata were removed by imgur, but I only can give that, thank you so much
I just ran into this issue. In my case the cause was the wrong encoding of the data in image parameter, it needs to be URL encoded (i.e. by using encodeURIComponent()).
My code uploads the contents of a Canvas object in PNG format and looks like this:
function encode(x)
{
return encodeURIComponent(x.substring(x.indexOf(",") + 1));
}
let xhr = new XMLHttpRequest();
xhr.onload = function(e) { console.log(e); };
xhr.onerror = function(e) { console.log(e); };
xhr.open("POST", "https://api.imgur.com/3/image");
xhr.setRequestHeader("Authorization", "Client-ID <your client id here>");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("image=" + encode(canvas.toDataURL()));

How to GET json data from API with a header

I'm trying to get JSON data from an API using NodeJS and Express, but it requires a header I'm not sure how to input the header into the get request.
The documentation says:
curl -H"X-FullContact-APIKey:$your_key"
'https://api.fullcontact.com/v2/person.json?email=bart#fullcontact.com'
How do I do a add a get request with a header? I looked everywhere on Stackoverflow for days, and havent found anything. Everything is for PHP, nothing for NodeJS w/ Express. How can I do this with the Request Node NPM Manager Package
Not sure on how your request code looks like, but this should do it; right?
var request = require('request');
var options = {
url: 'https://api.fullcontact.com/v2/person.json?email=bart#fullcontact.com',
headers: {
'X-FullContact-APIKey': '$your_key'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body);
console.log(result);
}
}
request(options, callback);

Telegram SetWebHook Self Signed Certificate

I'm Trying to Send a Self Signed Certificate To telegram .
The Configuration will be done through PostMan And My Bot Server is Ok (tests through getUpdates and action call over ssl connection responded successfully).
Here is what i send to telegram :
api.telegram.org/botMY TOKEN/setWebhook?url=MY SWERVER IP:443/api/webhook
and i DO attach the PUBLICKEY.pem as a binary body to the request.
Here is what i get :
{ "ok": true, "result": true, "description": "Webhook was set" }
the problem is when i check the webHook via getWebHookInfo :
{
"ok": true,
"result": {
"url": "94.183.157.125:443/api/webhook",
"has_custom_certificate": false,
"pending_update_count": 5,
"last_error_date": 1476206652,
"last_error_message": "Connection timed out"
}
}
in which the attribute "has_custom_certificate" : false means it did't get my certificate :\
What am i doing wrong here ?
Any alternatives to PostMan ??
One Step Further
I tried the HttpClient as below but it didn't work eighter :\
public string SetWebHook()
{
FileStream paramFileStream = new FileStream(#"E:\PATH.......\YOURPUBLIC.pem", FileMode.Open);
HttpContent fileStreamContent = new StreamContent(paramFileStream);
var response = string.Empty;
using (var client = new HttpClient())
using (var formData = new MultipartFormDataContent())
{
formData.Add(fileStreamContent, "Certificate", "YOURPUBLIC.pem");
response = client.PostAsync("https://api.telegram.org/botMYTOKEN/setWebhook?url=MYSERVERIP:443/api/webhook", formData).Result.ToString();
}
return response;
}
You must use curl to upload your certificate (pem)
And
You should use HTTPS:// for your url

Trouble with Mashape API using Google Apps Script

I've been using Google Apps Script for a little while now, but some how always get hung up on this payload thing. I'm just trying to to do a basic api call to mashape. Since it is a post call I'm pretty sure I should use the payload in the parameter-options, but just not really sure what's throwing me my error. Here is my code:
function mashapeTextSentiment(text){
var key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var url = "https://japerk-text-processing.p.mashape.com/sentiment/";
var language = "english";
var payload = {
"X-Mashape-Key": key,
"language": language,
"text": text
};
var options = {
"method": "post",
"payload": payload
};
var response = UrlFetchApp.fetch(url, options);
var rs = JSON.parse(response.getContentText());
return rs;
}
function testMashapeTextSentiment(){
Logger.log(mashapeTextSentiment("Someone please help me with this!"));
}
And this is the error it is giving me:
Request failed for https://japerk-text-processing.p.mashape.com/sentiment/ returned code 401. Truncated server response: {"message":"Invalid Mashape application key provided"} (use muteHttpExceptions option to examine full response) (line 17, file "Code")
I work at Mashape (disclaimer), I looked at ur code, it was a problem with the header - here's a working snippet!
All the best,
function mashape_all_things() {
var url = "https://japerk-text-processing.p.mashape.com/sentiment/";
var language = "english";
var text = "mashape's orlie is the great overlord"
var payload = {
"language": language,
"text": text
};
var options = {
"method": "post",
"headers": { //this is where you went wrong, you didnt pass the header properly
"X-Mashape-Key": "XXXXXXXXXXXXXXXXXX"
},
"payload": payload
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
return
}