cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FoDelement
Continued Contributor
Continued Contributor

HTTP request body not working

Hello,

 

I am trying to send an HTTP request of a file to a custom API. (Which works) but the contents of the file, in this case a PDF, becomes everything I put in the body. (including the braces)

 

FoDelement_1-1607640022874.png

"{
“body”: { %PDF-1.3 %..."

Any idea what I am doing wrong? 

Maybe @SamPo? 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
FoDelement
Continued Contributor
Continued Contributor

@yashag2255 

Hello again!

Hope you had a wonderful weekend!

I got it to work. The edits needed to be done in swagger.  (highlighted in bold)



/interactions/{Ticket}/attachments:
post:
responses:
default:
description: default
schema: {}
summary: Attachments
description: SendsAttachmentstoHPSM
operationId: Attachments
parameters:
- {name: Ticket, in: path, required: true, type: string}
- {name: Content-Disposition, in: header, required: false, type: string}
- {name: Content-Type, in: header, required: false, type: string}
- name: body
in: body
required: false
schema: {type: string, format: binary}
definitions: {}
parameters: {}
responses: {}
securityDefinitions:
basic_auth: {type: basic}
security:
- basic_auth: []
tags: []

once complete, I was able to pass this as the body.

FoDelement_0-1607980730448.png

 

View solution in original post

20 REPLIES 20
yashag2255
Dual Super User II
Dual Super User II

Hi @FoDelement 

 

Can you try passing the file content directly without any braces or keys and see if it is working that way?

 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

FoDelement
Continued Contributor
Continued Contributor

Hello!

When I try that, the file becomes corrupted.  😞

FoDelement_0-1607705432955.png

 

@FoDelement 

 

Have you tried achieving this with Postman (to send the file)? 

 

Can you try:

 

{

"body": filecontent

}

 

and get rid of the extra pair of {}

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

FoDelement
Continued Contributor
Continued Contributor

@yashag2255 

I have gotten it to work with Postman as a Binary file, as well as form-data. I also have no issue using C# to get the file attached. 

When I tried what you said, this happens.

The brackets and "body" make their way into the file.

 

 

FoDelement_0-1607707625744.png

 

Hi @FoDelement 

 

Would it be possible for you to share a screenshot from the Postman configuration? Regarding the headers and the body you are passing there? 

 

I believe you can then pass the binary directly by accessing the "$content" key from the outputs of the file content of the get file content action. 

 

If you could share the postman screenshot it would be easier to provide a better resolution for this. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

FoDelement
Continued Contributor
Continued Contributor

@yashag2255  I have spent two weeks trying to make this work. I am more than happy to share anything to make this work 🙂

I just sent a new request as form-data. The pdf uploaded just fine. The only header I need is the Content-Disposition and it needs to have the value of "attachment; filename=XXXXX" otherwise the API rejects it saying it does not have a file name. 

FoDelement_0-1607708744433.png

 

 

FoDelement_1-1607708790598.png

 

FoDelement_2-1607708812221.png

 



Hi @FoDelement 

 

Try this: 

yashag2255_0-1607712623568.png

 

From : https://powerusers.microsoft.com/t5/Building-Flows/HTTP-Post-multipart-form-data/td-p/145181

 

You already have the authentication from the HTTP Azure AD so just put everything in the body as in the screenshot and it should work. 

 

Hope this helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

FoDelement
Continued Contributor
Continued Contributor

@yashag2255 

Hello again! I tried what you said, (see below)

FoDelement_0-1607713227080.png


but the content of the PDF that is created contains the whole body of the request.

FoDelement_1-1607713286187.png

 

Which results in the PDF appearing to be corrupted. 

Since you are already passing the header in the body, can you remove it from the headers option on the action and try once?

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS! 

FoDelement
Continued Contributor
Continued Contributor

@yashag2255  

When I remove the headers, and only use them in the body I run into the issue where it requires that the Content-Disposition header has the required value of "attachment; filename=XXXXX" but it does not work. It's possible I am putting it in the wrong spot maybe? 

 

 

FoDelement_0-1607714608751.png

FoDelement_1-1607714623801.png

 

I believe that the issue here is the escape characters for the name that it is not picking up and in the reponse link I shared, there is another response you can check as shown below: 

 

yashag2255_0-1607715467188.png

 

You can get rid of everything in the body key and pass the attachment content there. 

 

Can you try this out once? 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

 

FoDelement
Continued Contributor
Continued Contributor

@yashag2255  The below returned the same error. "Attachment name is required" 

{
"$content-type": "multipart/form-data",
"$multipart": [
{
"headers": {
"Content-Disposition": "form-data; name=\"file\"; attachment; filename=\"test.pdf\""
},
"body:" {
"$content-type": "application/octet-stream",
"$content": "JVBERi0xLjMNJabp..."
}
}
]
}


Try this: 

 

{
"$content-type": "multipart/form-data",
"$multipart": [
{
"headers": {
"Content-Disposition": "form-data; name=\"file\"; filename=\"test.pdf\""
},
"body:" {
"$content-type": "application/octet-stream",
"$content": "JVBERi0xLjMNJabp..."
}
}
]
}

FoDelement
Continued Contributor
Continued Contributor

@yashag2255 Same issue. However, I know for a fact my API needs to have "Content-Disposition" with a value of "attachment; filename=XXXXX"

Okay! We will have to do some trial and error here. 

 

Can you do this: 

 

Put the header they way you have mentioned and 

 

Use the below in the body: 

 

{
"$content-type": "multipart/form-data",
"$multipart": [
{
"body:" {
"$content-type": "application/octet-stream",
"$content": "JVBERi0xLjMNJabp..."
}
}
]
}

FoDelement
Continued Contributor
Continued Contributor

So that when through now.  But the file does not open. When I inspect it in notepad++ this is the contents of the file.

You can see the whole body is once again becoming the contents of the file. 

 

 

FoDelement_0-1607718495542.png

 




yeah I get it. there is something obvious we are missing here. Let me try out a few things and see if I can find something. 

 

 

FoDelement
Continued Contributor
Continued Contributor

@yashag2255  No problem. I really do appreciate all the help so far. There seems to be little to no documentation on this anywhere!

Hi @FoDelement 

 

Can you try this? 

 

In the body of the http with azure ad action, directly pass this expression: 

 

outputs('Get_file_content')?['body']?['$content']
 
Here, the name of the action from where I am getting the file content is Get file content. You may have to change that in based on the name of your action. 
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,143)