Handle multipart/form-data in logic app standard Http action

Bob Wang 0 Reputation points
2024-11-21T07:56:25.68+00:00

In logic app standard, I'm following this MS learn page to call an api with multipart/form-data body from the previous "Create_CSV_table" action:

https://learn.microsoft.com/en-us/azure/connectors/connectors-native-http?tabs=standard#content-with-multipartform-data-type

On the right side is the sample config while on the left is mine:User's image

This returns a httpStatusCode 500: Outgoing HTTP request ends with server failure.

From raw input I can see all variables are parsed correctly (the body is simply the header row of the CSV):

    "method": "POST",
    "headers": {
        "Api-Key": "xxxxxxxxxxxxxxxxxxxxxxxx",
        "Authorization": "*sanitized*"
    },
    "body": {
        "$content-type": "multipart/form-data",
        "$multipart": [
            {
                "body": "Employee ID,Time Off,Date,Hours,Timestamp,IsDeleted\r\n",
                "headers": {
                    "Content-Disposition": "form-data; name=file; filename=LeaveDataTest.csv"
                }
            }
        ]
    }

After reading William's post here, I also tried replacing the body inside the $multipart with

"body": {
	"$content": "Employee ID,Time Off,Date,Hours,Timestamp,IsDeleted",
	"$content-type": "text/csv"
}

But this returned BadRequest - The provided workflow action input is not valid.

I tested the endpoint with Postman which supports attaching a physical file and that's the only thing worked. From the working call's snippet, there's a boundary added and encoding used, but I assume the Http action in logic app would do the same under the hood?

boundary = 'wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T'

dataList.append(encode('--' + boundary))

dataList.append(encode('Content-Disposition: form-data; name=file;')) Please explain a bit more as the original MS documentation is too brief.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,228 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.