PUT node bug with Microsoft graph API

Hello,

I’m trying to upload files into a SharePoint using the Microsoft graph API as it is explained there: https://docs.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0

Everything is working well except with the PUT node. Every time I’m trying to do the request to upload the file, I get an error 400 with an empty body response. But if I do the same request with the exact same parameter using the HTTP Retriever node from Palladian it’s working perfectly.

The thing is that I cannot use the Palladian node in Knime server because there is a license I cannot purchase for only 1 node.

Any idea why the PUT node is not working properly ?

I can provide more information if needed.
@szawadski

I used Fiddler to check the difference in the request between the Knime PUT node and the Palladian HTTP Retriever node.
Fiddler act as a proxy between Knime and the internet. I installed fiddler Root certificate to be able to decrypt the HTTPS requests. In the PUT node, I ticked the Trust all certificate to use that certificate.
And what do I see when the requests are going through Fiddler ? Well something unexpected, the PUT node is working properly and I don’ t get the error 400 anymore. When I do the request normally without going through Fiddler, I still get the error 400.

So I still don’ t know why I get that error 400 in the normal case. Does anywone knows why I have such a behavior and how I can fix this ?
@szawadski

And what if you trust all certificates without using Fiddler?
When you do not use Fiddler, have you noticed any difference depending on the fact you work behind a proxy or not?

1 Like

If I trust all certificates without using fiddler, I get an error 400.
If I work behind a rpoxy or not same, error 400 in both case.

Did you try the PUT node with any other REST API? I.e. does it happen only with Microsoft graph or in general on your machine?

I tried on different machines and different networks and still the same behavior. I haven’t tried a PUT request with something else than Microsoft graph. Do you have any idea of REST API where you can do a PUT request easily ? I will try to find something

We are using https://httpbin.org/ for testing the REST nodes. The PUT node works as expected with this service. The problem usually is that the service requires data to be formatted in a certain way, specific HTTP headers or similar. It’s almost impossible to tell where the problem is without a more detailed error message from the service.

1 Like

I tried httpbin with a PUT request and indeed it works.

The thing is that the body in the response from Microsoft graph API is empty for some reason. Here are all the headers:

And if I try to mess up with a compulsory request header in the HTTP retriever node I get the same error 400 but with the details in the body.

So yes I guess there is a small difference in the way the data are formatted between the PUT node and the HTTP retriever node. But how can I spot the difference if using Fiddler to observe what is going on is changing the thing I’m observing (see above)?

1 Like

You can try to change the URL to https://httpbin.org/anything for both the PUT Request node and the Palladian HTTP Retriever node and check whether there are any notable differences in the returned response. The response is basically a copy of the request including headers and data.

1 Like

So there was minor differences with the headers, some extra ones in the PUT Request node. I added those extra ones in the Palladian HTTP retriever so that the response from https://httpbin.org/anything was exactly the same for both nodes. Then, I put the url back to the microsoft graph API and still the same: request 200 with the Palladian HTTP retriever node and error 400 for the PUT request node. The data is also exactly the same.

So this means the error is not coming from the headers I guess. Any other ideas why it’s not working?

1 Like

Can you post the results of both class? Also, how large is the amount of data you are sending?

1 Like

This is the response from https://httpbin.org/anything for the 2 nodes. I removed the base64 string for the binary file under “data” because it’s quite big but they are the same in both case. The file is 1MB as you can see in Content-Length.

HTTP retriever node:

{
“args”: {},
“data”: “XXX”,
“files”: {},
“form”: {},
“headers”: {
“Accept”: “/”,
“Accept-Encoding”: “gzip,deflate”,
“Cache-Control”: “no-cache”,
“Content-Length”: “1048859”,
“Content-Range”: “bytes 0-1048858/1048859”,
“Content-Type”: “text/plain”,
“Host”: “httpbin.org”,
“Pragma”: “no-cache”,
“User-Agent”: “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5”
},
“json”: null,
“method”: “PUT”,
“origin”: “193.191.180.22, 193.191.180.22”,
“url”: “https://httpbin.org/anything
}

PUT request node:

{
“args” : { },
“data” : “XXX”,
“files” : { },
“form” : { },
“headers” : {
“Accept” : “/”,
“Accept-Encoding” : “gzip,deflate”,
“Cache-Control” : “no-cache”,
“Content-Length” : “1048859”,
“Content-Range” : “bytes 0-1048858/1048859”,
“Content-Type” : “text/plain”,
“Host” : “httpbin.org”,
“Pragma” : “no-cache”,
“User-Agent” : “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5”
},
“json” : null,
“method” : “PUT”,
“origin” : “193.191.180.22, 193.191.180.22”,
“url” : “https://httpbin.org/anything
}

1 Like

Hm, looks very similar. The reason why I was asking for the size is that the PUT Request node uses chunked encoding for larger bodies. This is standard HTTP technology but not all services support it unfortunately. However, I don’t think that chunking already starts at 1MB. Is it possible to send a much smaller request to the Microsoft API?

1 Like

Just tried with a 15ko file to the Microsoft API and no differences: error 400 with the PUT request node and 200 for Palladian HTTP retriever node. So not coming from the chunked encoding.
Note: all the other types of nodes works normally with the microsoft API (post and get)

1 Like

Hi @samuelVermeulen,

I know this is an old post but I am having the same problem.

I can complete at Graph API PUT request with files smaller than 4mb as configured here: https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http without issue.

The second I try the PUT request as documented here: https://docs.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0 I get nothing but 400 errors.

I have been wracking my brain and tried every configuration option I can think of with both POST and PUT nodes and have not had any luck.

Did you ever have any luck with a solution?

1 Like

I have still been working at this and found the following Blog that essentially solves the problem for me. I hope it can help others:

https://keathmilligan.net/automate-your-work-with-msgraph-and-python.

My workflow now incorporates reading in a file from SharePoint (using GraphAPI), running it through a workflow, saving to a TempDir then from that TempDir using a Python node to open an Upload Session (using Graph API) and successfully upload back/to SharePoint.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.