Upload attachments using API via Power Automate (resource subtype = "external")

Hey there,
I’m using MS Forms to create and update Asana tasks, with the integration configured via Power Automate. However, I’m encountering an issue when trying to upload an attachment from MS Forms to an Asana task using the upload attachment the endpoint: https://app.asana.com/api/1.0/attachments

The attachments either upload as a link when using ‘external’ as the subtype or as an actual file that is unreadable/unsupported when using ‘asana’ as the subtype.

Has anyone successfully uploaded an actual file using the external method? Here’s the code in my HTTP request for reference:

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"parent\""
      },
      "body": "@{variables('myVariable')}"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"resource_subtype\""
      },
      "body": "external"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"url\""
      },
      "body": "@{items('Attachment-Get_file_content_and_add_to_task')['link']}"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"name\""
      },
      "body": "@{outputs('Attachment-Get_file_metadata')?['body/Name']}"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=\"@{outputs('Attachment-Get_file_metadata')?['body/Name']}\"",
        "Content-Type": "@{body('Attachment-Get_file_content_and_add_to_task')?['$content-type']}"
      },
      "body": "@{body('Attachment-Get_file_content_and_add_to_task')?['$content']}"
    }
  ]
}

Thanks in advance,
Daniel

Hi @Daniel_Perez,

Check out this post and see if it helps:

1 Like

Thank you, @Phil_Seeman !
I’m still getting the same result. See the attach image:

So, the first one looks correct, but when opening the file, it says it’s not supported (this happens with Excel or image files). The second one is actually the hyperlink to where the file is hosted, and it works, but it becomes uncomfortable for the user when files like images are uploaded.

Ideally, I’d like to get it uploaded as an actual file.

Thank you,
Daniel

Hi @Andrew_Pegram
Looks like you were able to solve this issue. Are you encoding the file in any way? How does it get attached to the task? As the file as such? Or as a link?

Any insight is greatly appreciated!
-Daniel

I literally fixed it while posting the question! :melting_face:
@Phil_Seeman , @Andrew_Pegram, I removed the quotes around the content file as per Andrew’s post. Additionally, I encoded it using the base64ToBinary function in the expression. The final expression looks like this:
*base64ToBinary(body('Attachment_Get_file_content')?['$content'])*

I hope this can help anyone else!
-Daniel

1 Like

That’s great news, @Daniel_Perez! And thanks for posting your solution for others who follow here.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.