InvalidRequestContent in Postman when POSTing file - post

I am trying to upload a file and send it with a POST request. The backend is Powerautomate flow, but nothing, except the txt file, reaches it. If I try to upload (pdf, png, jpg…) it gives me the error code InvalidrequestContent and the message "The input body for trigger 'manual' of type 'Request' must be of type JSON, but was of type 'application/pdf'." - depending on the file format.
I tried different files and only the .txt file will return 204, otherwise 400 (files are very small - 4 bytes)
I tried to upload as binary as well as form-data. Any suggestions?

Related

Microsoft Graph (OneDrive) API - Resumable Upload Content-Type

I am trying to create the upload PUT request for the OneDrive API. It's the large file "resumable upload" version which requires the createUploadSession.
I have read the Microsoft docs here: As a warning the docs are VERY inaccurate and full of factual errors...
The docs simply say:
PUT
https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337Content-Length:
26Content-Range: bytes 0-25/128 <bytes 0-25 of the
file>
I am authenticated and have the upload session created, however when I pass the JSON body containing my binary file I receive this error:
{ "error": {
"code": "BadRequest",
"message": "Property file in payload has a value that does not match schema.", .....
Can anyone point me at the schema definition? Or explain how the JSON should be constructed?
As a side question, am I right in using "application/json" for this at all? What format should the request use?
Just to confirm, I am able to see the temp file created ready and waiting on OneDrive for the upload, so I know I'm close.
Thanks for any help!
If you're uploading the entire file in a single request then why do you use upload session when you can use the simple PUT request?
url = https://graph.microsoft.com/v1.0/{user_id}/items/{parent_folder_ref_id}:/{filename}:/content
and "Content-Type": "text/plain" header and in body simply put the file bytes.
If for some reason I don't understand you have to use single-chunk upload session then:
Create upload session (you didn't specified any problems here so i'm not elaborating)
Get uploadUrl from createUploadSession response and send PUT request with the following headers:
2.1 "Content-Length": str(file_size_in_bytes)
2.2 "Content-Range": "bytes 0-{file_size_in_bytes - 1}/{file_size_in_bytes}"
2.3 "Content-Type": "text/plain"
Pass the file bytes in body.
Note that in the PUT request the body is not json but simply bytes (as specified by the content-type header.
Also note that max chuck size is 4MB so if your file is larger than that, you will have to split into more than one chunks.
Goodlcuk

HTTP error 405 when trying to create an apload session with MS Graph API

I am trying to upload a large attachment with Microsoft Graph Rest API.
I am able to create an upload session and attach a large file > 3 Mo (file attachment) but when i try to create an upload session to attach an item with a size > 3 Mo to a mail, it fails with an error 405. The Reason is because i'm setting the attachment type to "item" instead of "file". When i try to POST to the API endpoint the Following payload (for testing):
{"AttachmentItem":{"attachmentType":"item","name":"flower","size":3483322}}
The response (with a 405 status) is:
{"error":{"code":"ErrorAttachmentSessionIsSupportedOnlyForFileAttachments","message":"Unsupported Attachment type specified. Only File attachments can be uploaded using an Upload Session.","innerError":{"date":"2020-12-09T16:03:11","request-id":"ded65db1-179f-45bd-89ba-e5527556f359","client-request-id":"f6befc74-8399-227d-3686-bf2a62297a44"}}}
Normally the "item" attachment type should be supported according to the documentation (https://learn.microsoft.com/en-us/graph/api/resources/attachmentitem?view=graph-rest-1.0).
Any clue on this ?
Thx

How to fix error 400 "file not found" when sending file to api endpoint on a REST POST snap on snaplogic?

I am trying to send a csv file from snaplogic to an api endpoint using through a REST POST snap but it doesn't seem to actually send the file as the response says file not found
when I do the post through postman it just fine and use the same information I use in the snap
my settings in the POST snap are as follows:
Label*= REST Post Service URL*=http://(ip:port)/v1/innovazones HTTP
entity=(blank) Batch size=(blank) Show all headers(selected) Single
file upload: File=…/shared/TEMPcsv.csv Single file upload: File
key=file Single file upload: Filename to be used=innovaZones_csv_file
Upload transfer request type=calculate content length Upload body
type=Multipart form data Single file upload: Multipart Content-Type=text/csv
HTTP header:
Key=Content-Type;Value=application/x-www-form-urlencoded
key=Authorization Value="Bearer " + account.access_token
Trust all certificates*(checked) Follow redirects*(checked)
I should be getting this message:
{
"status": "success",
"message": "Data transmitted successfully",
"payload": {}
}
but I get this in the response instead:
"error": "REST API service endpoint returned error result: status code = 400, reason phrase = Bad Request"
"error_entity": {
"status":"fail",
"message":"File not found",
"payload":{
"message":"File not found",
"statusCode":400,
"status":"fail"
}
}
"original": {filename:../shared/TEMPcsv.csv, result:overwritten, original:{, ...}}
"filename": "../shared/TEMPcsv.csv"
"result": "overwritten"
You have not added the actual files to upload. You have only set the name of the file.
As per the SnapLogic documentation -
Single file Upload: Filename to be used
This property can be configured if you are uploading a file, the value entered in this field will be treated as the name for the file being uploaded. You can retain the original file name by leaving this property blank.
What you also need to do is point to the actual file you want to upload in the Upload file(s) section.
Again, from SnapLogic documentation -
Upload File(s)
Lists out the file keys and file names of the files that you want to upload. By default, the Settings popup displays the fields required to upload a single file. Click the + button to add new rows to this fieldset. For each file that you want to upload, you need to specify the upload-file key, the location and name, the name of the file in the destination directory, and the multi-part content type associated with the file that you want to upload.
Please refer to - SnapLogic Docs - REST POST

Microsoft graph: Resumable upload doesnt work if the file name contains Norwegian character(ø)

I am using resumable file upload which works fine for files without Norwegian character in it. If the file name has Norwegian character in it the uploadSession is established and after that when I sent the content on the uploadUrl returned from upload session request the call fails and gives the following error.
{
"error":"invalid_request",
"error_description":"This access token is not valid on this endpoint."
}
However from the same file if I remove this character (ø) everything works fine.
This the sample url returned from the createUploadSession endpoint.
https://<sharepoint_sitename>/sites/jnu/_api/v2.0/drives/b!uey_5Lpf8Eu0-5HlGvJvFga89s_hTxNAg9kSsTlOBqajRqOF3ec-Rp6uqtbLNt4w/items/016GMDDVAF3UIOU2YNWVE3TX24ZV44WN4K/uploadSession?guid=%274ce82b5c-ede4-4d1d-af0a-6ff3b33c10b7%27&path=%27%7etmp41_Decisions+-+Advania+sdfsldfasduftest%u00f8+a%27&overwrite=True&rename=False&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZmlnZy5zaGFyZXBvaW50LmNvbUBjNzEwNWRkYS1hNTQ4LTRkZWYtOGVlNy1lOTkyZTBlNmRjYjAiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAiLCJuYmYiOiIxNTAyMDk4NDM0IiwiZXhwIjoiMTUwMjE4NDgzNCIsImVuZHBvaW50dXJsIjoiQ1A3T2Q0OVBKR25Scy9TbnN0akNUbk5BV29KeEJhdzFVNnNCTHY5SG5oND0iLCJlbmRwb2ludHVybExlbmd0aCI6IjMwMiIsImlzbG9vcGJhY2siOiJUcnVlIiwiY2lkIjoiWW1JMk1tUTFaamd0TkRZMllpMDBaR1JtTFdJM1lqY3ROVE5qWTJNMU1UZ3lNbU5qIiwidmVyIjoiaGFzaGVkcHJvb2Z0b2tlbiIsInNpdGVpZCI6IlpUUmlabVZqWWprdE5XWmlZUzAwWW1Zd0xXSTBabUl0T1RGbE5URmhaakkyWmpFMiIsIm5hbWVpZCI6IjAjLmZ8bWVtYmVyc2hpcHxkZWVwYWsuc2hhcm1hQGRlY2lzaW9ucy5ubyIsIm5paSI6Im1pY3Jvc29mdC5zaGFyZXBvaW50IiwiaXN1c2VyIjoidHJ1ZSIsImNhY2hla2V5IjoiMGguZnxtZW1iZXJzaGlwfDEwMDM3ZmZlOTY2MjcxYmNAbGl2ZS5jb20iLCJ0dCI6IjAiLCJ1c2VQZXJzaXN0ZW50Q29va2llIjpudWxsfQ.MTl0bEZ6cldwUlZEVUkwcEphUkpnWDRVelNnWnFWQndlVEtpbG9ndlhLYz0
This was a regression introduced when the session URLs were updated to a new format - it should now be fixed!

How to upload a file in Telegram Bott api using Http client?

I have tried to send files using multipart form data, but all I get is the following error:
{"description":"Error: Bad Request: chat_id is empty","error_code":400,"ok":false}
Here is my code snippet. Can anyone help me out where I am committing an error?
public HttpResponse<jsonnode> sendDocument(Integer chat_id,File f1) throws UnirestException {
return Unirest.post(endpoint + token + "/sendDocument")
header("accept", "application/json")
.field("chat_id", chat_id)
.field("document", f1)
.asJson();
}
well, it said chat_id is empty. that's an obvious error!
but for your question, there is only two ways to sendDocument to telegram.
that file is already is in their servers, so you should just pass the file_id in "document" field
you want to upload a file from your device and as they said
Must be posted using multipart/form-data in the usual way that files are uploaded via the browser
if you are doing the upload section correct, then just make sure chat_id is not empty.

Resources