Add file API -> How should the request body look like?

Hello Everybody, 

I want to upload a file to HighQ with Power Automate.

I had no problem to solve this with Postman, but I have no clue how the body XML of the request should look like.

Currently I get the response, that my xml is not valid.

<file>here is the file content</file>

<filename>hieristhefilename.png</filename>

What <attributes> do I need to put on start and end of the body?

I studied all documentation (old and new stuff), but the information about the request body of all the endpoints are very poor. 

Every help is much appreciated. Thank you,

Philipp

Parents
  • 0
    Thomson Reuters Thomson Reuters staff member

    Hi,

    We are using only Swagger and postman to test and execute the endpoints. We are not yet familiar with Power Automate and our development team started exploring on this. Meanwhile we found some community post regarding uploading file using Power automate and it might be helpful.

    Solved: HubSpot Community - Uploading a file using Power Automate - HubSpot Community

  • Solved!

    After some hours learning about multipart/form-data, and an important hint by  /  / EngineerLegal I know have a working code:

    {
    "$content-type": "multipart/form-data",
    "$multipart": [
    {
    "headers": {
    "Content-Disposition": "form-data; name=\"filename\""
    },
    "body": "file.png"
    },
    {
    "headers": {
    "Content-Disposition": "form-data; name=\"file\";filename=\"file.png\""
    },
    "body": "@{variables('FileBase64')}"
    }
    ]
    }

    Important:

    1.the two parameters file and filename must be sent in two seperate parts.

    2. the file parameter also needs the filename in "content-disposition" (you get a 403 if you don't do it)

    3. in this code the filename is static, you might change this to a variable

    4. the file content must be transformed to binary format.

    5. " in content-dispostion must be escaped \"

    Thanks again to Dan / EngineerLegal for the last hint! 

  • Reply
    • Solved!

      After some hours learning about multipart/form-data, and an important hint by  /  / EngineerLegal I know have a working code:

      {
      "$content-type": "multipart/form-data",
      "$multipart": [
      {
      "headers": {
      "Content-Disposition": "form-data; name=\"filename\""
      },
      "body": "file.png"
      },
      {
      "headers": {
      "Content-Disposition": "form-data; name=\"file\";filename=\"file.png\""
      },
      "body": "@{variables('FileBase64')}"
      }
      ]
      }

      Important:

      1.the two parameters file and filename must be sent in two seperate parts.

      2. the file parameter also needs the filename in "content-disposition" (you get a 403 if you don't do it)

      3. in this code the filename is static, you might change this to a variable

      4. the file content must be transformed to binary format.

      5. " in content-dispostion must be escaped \"

      Thanks again to Dan / EngineerLegal for the last hint! 

    Children
    • Here is a updated version of my file post code. I just finished the whole process and I am now able to copy a file from one site to another site with all relevant metadata. Adaption for source site and recipient site is done in a couple of minutes, maybe a hour. 

      Must crutial step for me, was that, the pdf in the recipient site was broken/currupt and it took me two days to find the mistake: The" " at the $content variable where wrong. Solved: Send email with document PDF - attachment is corrupted (powerplatform.com)

      {
      "$content-type": "multipart/form-data",
      "$multipart": [
      {
      "headers": {
      "Content-Disposition": "form-data; name=\"filename\""
      },
      "body": "@{variables('documentname')}"
      },
      {
      "headers": {
      "Content-Disposition": "form-data; name=\"file\";filename=\"@{variables('documentname')}.@{variables('documentextension')}\"",
      "Content-Type": "application/pdf"
      },
      "body": {
      "$content-type": "application/octet-stream",
      "$content": @{body('HTTP_3')?['$content']}
      }
      }
      ]
      }