Logic app HTTP post request with two files

Sarah Cummings 45 Reputation points
2023-11-28T20:59:04.9066667+00:00

I need to post to an API with two files. In a previous iteration of my app, I only needed to post one file so using my http connector I created a body like this:

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "body": @{outputs('Compose_-_convert_for_skim_and_trim')},
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=\"@{body('Create_blob_(V2)_-_original_file')?['DisplayName']}\""
      }
    }
  ]
}

How would I modify the body to account for an API wthat takes two inputs? For example, locally, I can post to the api with the following curl command:

curl -F "pdf=@scratch/input.pdf" -F "matchers=@scratch/matchers.json" <myapi.com> -o output.pdf

What would the body look like in the logic app post request to replicate this request? Assuming I had the second file also in a "compose"

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

1 answer

Sort by: Most helpful
  1. Mike Urnun 9,786 Reputation points Microsoft Employee
    2023-11-29T01:20:12.1866667+00:00

    Hello @Sarah Cummings - Thanks for reaching out, and posting on the MS Q&A. I'm looking into your use case and will share my findings shortly.

    UPDATE: You would add another JSON object (describing the second file) to the $multipart array such that the entire JSON would look as follows:

    {
      "$content-type": "multipart/form-data",
      "$multipart": [
        {
          "body": "contents of a file 1",
          "headers": {
            "Content-Disposition": "form-data; name=\"file1\"; filename=\"file1_name.txt\"",
            "Content-type":"text/plain"
          }
        },
        {
          "body": "contents of a file 2",
          "headers": {
            "Content-Disposition": "form-data; name=\"file2\"; filename=\"file2_name.txt\"",
            "Content-type":"text/plain"
          }
        }
      ]
    }
    
    
    

    Please "Accept Answer" if the answer is helpful so that others in the community may benefit from your experience.

    0 comments No comments