Adding attachment to Asana task from Power Automate

Hi,

Is there some “trick” to add attachment to a task created from Microsoft Power Automate?

If not, could I somehow “write” some code to make Power Automate insert a link instead?
I can insert a sharing link to a document in Sharepoint but it can be long URL.

Hi,

I believe PowerAutomate has the ability to do what’s called “HTTP request”, which is a way of saying that you can talk to the Asana API and whatever you need. Here’s the documentation.

I can help as a consultant/developer on that matter!

I have tried to use the HTTP POST action in Power automate. However I still get the error code 400 url: missing input.

{
    "statusCode": 400,
    "headers": {
        "Connection": "keep-alive",
        "pragma": "no-cache",
        "X-Frame-Options": "DENY",
        "X-XSS-Protection": "1; mode=block",
        "X-Content-Type-Options": "nosniff",
        "Content-Security-Policy": "report-uri https://app.asana.com/-/csp_report?report_only=false;default-src 'none';frame-src 'none';frame-ancestors 'none'",
        "X-Asana-Api-Version": "1.0",
        "Asana-Change": "name=new_user_task_lists;info=https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828,name=new_project_templates;info=https://forum.asana.com/t/a-new-api-for-project-templates/156432",
        "X-Robots-Tag": "none",
        "Cache-Control": "no-store",
        "Date": "Tue, 21 Feb 2023 15:13:59 GMT",
        "Server": "nginx",
        "Content-Length": "185",
        "Content-Type": "application/json; charset=UTF-8"
    },
    "body": {
        "errors": [
            {
                "message": "url: Missing input",
                "help": "For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"
            }
        ]
    }
}```


![image|479x500](upload://jg3euFwLm82ltSblmiouwmJ6PQa.png)

In the http body i have tried using "sharing link to the sharepoint document" in the field "download_url". In this example I have tried to encodeURIComponent the sharing link. 

I have access to the sharing link itself and I have also tried more simple links like https://<org>.sharepoint.com/sites/folder/document.pdf

Is it possible to add sharepoint documents as an attachment into a Asana task with Power Automate ?

You should first work with Postman to come up with the right request, or even use the embedded tool in the documentation. Once you have the right request, you can replicate it into Power Automate. It will be way more confortable.

1 Like

HI Patrick, Did you figure that out? I’m having a similar problem and am having trouble converting curl from documentation to JSON need in Power Automate’s HTTP action.

I too am having trouble with this.

My flow is to take an input from a Microsoft Form, feed the responses into a Word document form, convert that to PDF, then attach it to a new task in Asana. Everything else works perfectly (this flow used to create a Sharepoint item and attach the PDF to that). The task is created in Asana, the Word document is filled in, it’s converting to PDF properly.

But in all my testing, I cannot seem to get Power Automate to attach any file to the task in Asana.

I’ve found the “proper” way to convert the multipart/form-data to a JSON object that Power Automate can process, but I’m still getting an error:

{
  "errors": [
    {
      "message": "file: File is not an object",
      "help": "For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"
    }
  ]
}

Here’s the body of my request, which to my knowledge is in the correct format for Power Automate:

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "body": "@{outputs('Create_Task_(V2)')?['body/gid']}",
      "headers": {
        "Content-Disposition": "form-data; name=@{outputs('quote')}parent@{outputs('quote')}"
      }
    },
    {
      "body": "data:application/pdf;name=form.pdf;base64,@{base64(body('Convert_Word_Document_to_PDF'))}",
      "headers": {
        "Content-Disposition": "form-data; name=@{outputs('quote')}file@{outputs('quote')}",
        "Content-Type": "application/pdf"
      }
    },
    {
      "body": "asana",
      "headers": {
        "Content-Disposition": "form-data; name=@{outputs('quote')}resource_subtype@{outputs('quote')}"
      }
    }
  ]
}

Anyone have any ideas or experience with this?

For further clarification, this error message is also received when I send requests from Postman, including using the data copied directly from the API Explorer (which works)…

I’m getting closer. The correct format for the body of the HTTP Request action is as follows:

{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"parent\""
      },
      "body": "@{outputs('Create_Task_(V2)')?['body/gid']}"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=\"<file name>\"",
        "Content-Type": "application/pdf"
      },
      "body": "<file data>"
    }
  ]
}

Now, a file is created, but the document is blank. I think it’s a character encoding problem…

I figured it out. The problem was the quotes around . In my flow, I had the following line:

 "body": "@{body('Convert_Word_Document_to_PDF')}"

It should be:

 "body": @{body('Convert_Word_Document_to_PDF')}

For posterity, anyone trying to attach a PDF to an Asana task using Power Automate, this is how you should do it:

  1. Process your data and create your attachment (I used the Word Online actions to populate a template and convert to PDF)

  2. Create a task using the Asana connector

  3. Create an HTTP action:

    • Method: POST
    • URI: https://app.asana.com/api/1.0/attachments
    • Headers:
      • Authorization: Bearer <API key>
      • Accept: application/json
    • Body:
{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"parent\""
      },
      "body": "@{outputs('Create_Task_(V2)')?['body/gid']}"
    },
    {
      "headers": {
        "Content-Disposition": "form-data; name=\"file\"; filename=\"<filename>.pdf\"",
        "Content-Type": "application/pdf"
      },
      "body": @{body('Convert_Word_Document_to_PDF')}
    }
  ]
}

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