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

  • 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! 

  • 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']}
    }
    }
    ]
    }

  • Here’s a general approach for structuring an XML request body for a file upload, based on common practices. This might need adjustments depending on the HighQ API's exact requirements.

    Example XML Body Format for File Upload:

    xml
    Copy code
    <UploadFileRequest> <file> <![CDATA[BASE64_ENCODED_FILE_CONTENT]]> </file> <filename>hieristhefilename.png</filename> <attributes> <attribute1>value1</attribute1> <attribute2>value2</attribute2> <!-- Add more attributes as needed --> </attributes> </UploadFileRequest>

    Explanation:

    1. <UploadFileRequest>: This is the root element. The actual root element will depend on HighQ’s documentation, but typically, APIs define a request structure with an identifying root element.

    2. <file>: The file content is often included here, potentially Base64-encoded if the API requires it. Check whether HighQ requires you to Base64 encode the file content.

    3. <filename>: The file’s name. You seem to already be doing this correctly.

    4. <attributes>: This can be used to add additional metadata or parameters if needed, like file type, description, etc. If the API documentation specifies particular attributes, you should add them here.

    5. <![CDATA[ ... ]]>: In case the file content includes characters that might be misinterpreted as XML (like &, <, >), it’s good to wrap it in <![CDATA[ ... ]]> to ensure it’s treated as plain text.


    Things to Check:

    1. Encoding the File: Ensure the file is properly Base64-encoded if that’s what the API requires.

    2. HighQ Documentation: You might be missing some specific attribute or structural element required by HighQ. Some APIs require multipart/form-data or specific content types.

    3. Content-Type Header: When you are working with Power Automate, make sure to set the correct content type in the headers, often application/xml or multipart/form-data, depending on the API's specification.

    I am a developer and Academic writer at Nerdpapers. If you have more details from the documentation or the exact error response, feel free to share them, and I can help refine the solution further!