Howto do multipart/formdata upload in (new) generally available Logic App designer

Erwin Dijkstra 0 Reputation points
2024-09-18T14:35:20.7466667+00:00

I have a Logic App in which I call an operation in API management to upload a document and several properties.

This works just fine in the 'old' Logic App designer.

When I switch to the new Logic App designer, the code is removed upon saving. So I need to rewrite the code in a format, so that the multipart/formdata upload keeps working. In the new designer a required property 'FormData' is shown in the interface, but which data should I enter here to get correct behaviour?

When I search online, I keep finding that formData should not be used in OpenApi v3.0.x and that I should use requestBody (which is exactly what I'm using in my current code). Can someone clarify?

API definition (OpenAPI JSON v3.0.1):

    "/documents/file": {
      "post": {
        "tags": [
          "Documents"
        ],
        "summary": "Create File Based Document",
        "description": "Create File Based Document",
        "operationId": "create-file-based-document",
        "parameters": [
          {
            "name": "Content-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "multipart/form-data"
            }
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "properties": {
                  "file": {
                    "type": "string"
                  },
                  "labelId": {
                    "type": "string"
                  },
                  "ownerId": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document created",
            "content": {
              "application/json": {
                "example": {
                  "data": 0,
                  "meta": {
                    "status": "string",
                    "code": 0,
                    "requestDate": "string"
                  }
                }
              }
            }
          }
        }
      }
    },

Code in 'old' editor to call API:

{
    "inputs": {
        "method": "post",
        "body": {
            "$content-type": "multipart/form-data",
            "$multipart": [
                {
                    "body": "@body('Get_blob_content_(V2)')",
                    "headers": {
                        "Content-Disposition": "form-data; name=\"file\"; filename=@{body('Get_Blob_Metadata_(V2)')?['Name']}"
                    }
                },
                {
                    "body": "@variables('DocumentType')",
                    "headers": {
                        "Content-Disposition": "form-data; name=\"labelId\""
                    }
                },
                {
                    "body": "@body('get-databyusername')['data']['id']",
                    "headers": {
                        "Content-Disposition": "form-data; name=\"ownerId\""
                    }
                },
                {
                    "body": "@body('Parse_JSON')?['DocumentType']",
                    "headers": {
                        "Content-Disposition": "form-data; name=\"description\""
                    }
                },
                {
                    "body": "@body('Get_Blob_Metadata_(V2)')?['Name']",
                    "headers": {
                        "Content-Disposition": "form-data; name=\"filename\""
                    }
                }
            ]
        },
        "headers": {
            "Content-Type": "multipart/form-data"
        },
        "pathTemplate": {
            "template": "/api-rest/v1/documents/file",
            "parameters": {}
        },
        "api": {
            "id": "/subscriptions/<
Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,175 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,211 questions
{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.