Error 400 Invalid request with upload url but file is properly send to sharepoint - sharepoint

I try to send a file to sharepoint using the Microsoft Graph API resumable file upload :
First, I create my upload session POST: https://graph.microsoft.com/v1.0/me/drive/root:/{itemid}/createUploadSession and I get my upload url, no problem here.
I call my upload url PUT: https://xxx-my.sharepoint.com/personal/xxx_onmicrosoft_com/_api/v2.0/drive/items/xxxxxxxxxx/uploadSession?guid='xxxx'&overwrite=True&rename=False&dc=0&tempauth=xxx with some parameters: Content-Length and Content-Range
I get this error, code 400 : {"error":{"code":"invalidRequest","message":"Invalid request"}} but if I take a look to my sharepoint, the upload did create it! I tried to add or remove parameters, change PUT to POST but of course, it's not working (got DeferCommit was set to false for this upload session., which seems to be normal if I call the upload url with POST).
If I look to the error message, I just have Bad Request with no more informations. I don't know what I'm doing wrong or what I'm missing. If you have some insights, please do tell!!

I found what was missing! I need to add this header to my request: Accept with the value application/json. Now it works like a charm!

Related

Add sample image in template header in whatsapp cloud API

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node JS.
Template with a media header
Add sample image for a template
curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
?name={template-name}
&language=en_US
&category=TRANSACTIONAL,
&components=[{
type:BODY,
text:{message-text}
},
{
type:HEADER,
format:IMAGE,
example:{header_handle:[{uploaded-image-file-url}]}
}],
&access_token={system-user-access-token}"
I want to add a sample image using Node JS (Not manually like the second picture).
header_handle requires a encrypted file upload provided by facebook.
This can be done by calling 2 apis.
First,
We have to create a session for the file to be uploaded.
For creating session refer this
After creating session, we will get session id to upload the original file to it.Response will look something like this:
{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}
Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}
This will give a response something similar to
{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}
Finally,
{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}
Should be added during the request to create template.
It worked for me.
See this for better understanding on how to do it.
The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.
Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)
Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.
I have tested it and it works for me.
Hope this helps

Downloading attachment from card at Trello Python3

I've got a problem that unables me to download attachment.
Via API I can Upload file as attachment, but instead of authorising via Oauth, I can get attachment, by it's ID, i got accept, but I cannot in response got any answer.
The way I do:
response = requests.get(f'https://api.trello.com/1/{card_id}/attachments/{id_of_attachment}', header, allow_redirects=True, auth=self.o_oauth)
header is dictionary which is:
empty,
or authorisation,
or authorisation and "fields": url_of_attachment
On every of this questions to Trelo I got access, and 200 Response. But in response there was no place where I could find my file (I'm uploading this in the same test, and I got accept).
Where, and how should I look for content?

Azure Maps Static Image service API issue, "invalid format" from the Data Upload API

I try to render data on a static Azure Map. I followed this tutorial
I can successfully upload the Geo.json to the static map API and do a request to check the upload status. However in the documentation is stated that I should receive a response like this:
{"udid" : "{udId}"}
The actual response I get is:
{"operationId": "{udId}"}
The next step is to call the static map API to request the plotted image, however I cannot complete this step since the API is giving a 400 error bad request. I have tried with "udid-" and "operationId-" but both give the same error. The call looks like:
https://atlas.microsoft.com/map/static/png?subscription-key={key=hidden}version=1.0&layer=basic&style=main&zoom=12&center=5.356764766897979,53.05137698634611&path=lc0000FF|fc0000FF|lw3|la0.80|fa0.30||operationId-{udId=hidden}
It looks like the documentation is not up-to-date or I did something wrong.
Looks like that tutorial is missing a step. After step 5 you have to grab the "Resource-Location" URL that's in the header of the operation response which points to the operation metadata. That will have the UID value in it. It will look something like this: https://us.atlas.microsoft.com/mapData/metadata/e0020b05-1f9b-5a8f-260f-87b7ef461432?api-version=2.0
Append your &subscription-key={your key} to that URL, and you will see the UID.
Alternatively, that GUID in the metadata URL is actually the UID, so you could parse it out instead of calling that service.

php library for flickr API

I am banging my head trying to use Flickr API...
My goal is to be able to upload images and create albums in my Flickr account from my website...
I tried the phpFlickr library but apparently it needs updates for getting authenticated tokens...It keeps giving me "Invalid auth token".
I did some reading on how to get tokens and using DPZFlickr managed to get oauth_token & oauth_verifier but failed to exchange that with an access token...It also failed in uploading any photo to my account using the included upload.php example (Giving me an "empty" error!).
After digging in DBZ flickr.php code, I managed to get this error when trying to upload to Flickr: "oauth_problem=signature_invalid&"
So I began to search how to create a valid signature to eventually get a valid access token...and concluded that it is quite some work to be done here if I am going to build everything from scratch.
So my question is: Are there any updated php libraries that I can use to successfully create albums and upload photos to my Flickr account? Or should I go ahead and try building one?
OK..I finally got it to work with the DPZ library.
For future reference anybody facing the same problem as I had:
I managed to create an album using DPZFlickr by changing the method in auth.php to flickr.photosets.create....which indicated that the library correctly generates an access token with write permission..
However, the upload example kept giving me the "Invalid signature" error....
I checked the code. Flickr.php correctly unsets the photo parameter before signing the request then adds it back and submits the request which is exactly as indicated in: www.flickr.com/services/api/upload.api.html
I found a discussion in https://www.flickr.com/groups/51035612836#N01/discuss/72157650261711318/ that cleared out that the error was not actually a signature problem, but rather the 'photo' parameter that is being sent is the problem. It's just that Flickr doesn't know what to do with the photo parameter so it sends the signature error.
So what' wrong with the photo parameter?
Flickr API requires that the image has to be sent in binary form...The DBZ library, Flickr.php script line 677, does the hard work for us using the cURL function in php (http://au.php.net/manual/en/function.curl-setopt.php).
It sends the $parameters (which includes the uploaded photo) to the post field of the http request which should do the upload in binary format for us.
However, a brilliant comment I found in CURL PHP send image
states that:
"CURLOPT_SAFE_UPLOAD defaulted to true in 5.6.0... so you will need to add curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); before setting CURLOPT_POSTFIELDS"
Checking the manual: http://au.php.net/manual/en/function.curl-setopt.php
it says:
"Added in PHP 5.5.0 with FALSE as the default value. PHP 5.6.0 changes the default value to TRUE."
So if your php version is 5.5.0 the library will work just fine whilst if using version PHP 5.6.0 you need to add a line before 677 in Flickr.php to change the CURLOPT_SAFE_UPLOAD to false (that's why the library works with some and others not).
To solve the issue...Just add this line before line 677 in Flickr.php:
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
That's it. (-:

HTTP Error 405.0 - Method Not Allowed while Form Post

I posted a request to payu server via form submit using angularjs now once payment is completed payu will return a response with hash.But when it hits my success page i get "HTTP Error 405.0 - Method Not Allowed".I found many solutions online but none of that solved my issue.What i understood is that static html do not allow post by default.But my staticFile in IIS is like below
Request Path : *
Module : StaticFileModule
Name : staticFile
Request Restriction >Verb > All Verbs & Access > Script & Invoke > Files and folders
My question now in how to allow POST method for html page.I am using angular and if i change my success url to other than mine it works fine.I think there is some changes to be made to the web config but i tried my best but failed.Any help would be much appreciated.Also lets assume that the page successfully redirects to my success page how to capture the response that payu sends me online.
Thanks in advance if more input is needed from my side kindly ask in reply.
It's not that HTML does not allow POST by default, it's that HTML does not handle POST, period. (Not even if the HTML file contains JavaScript.) POST sends data to a script that runs on your server, and the script has to be smart enough to know what to do with the data. HTML isn't that smart. The only thing your server can do with HTML is to send the HTML back to whatever is requesting it. You need a server-side script that knows how to parse payu's response, do something appropriate with the hash, and then generate some HTML to display in the user's browser.

Resources