web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Adding Attachments fro...
Power Automate
Answered

Adding Attachments from MS Forms to DevOps via Flow

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Currently, I have a MS Form that is getting some information to pass through a flow to create a task in Azure DevOps.  Currently, my flow is:  

When a new response is submitted

Get Response details

HTML to text (form options to remove any html issue)

Send an HTTP request to Azure DevOps

 

In the HTTP Request, I have:

POST

URI: /ProjectName/_apis/wit/workitems/$task?bypassRules=true&api-version=6.0

Headers:  Content-Type - application/json-patch+json; Accept - applications/json

Body Ex: [
{
"op":"add",
"path": "/fields/System.Title",
"value":"Subject here"
},

,
{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "AttachedFile",
"url": " ",
"attributes": {
"comment": "Try This",
}
}

 

In the url, I have an expression getting the URL.  When I run the flow, it displays the correct url but it won't add the attachment.  I've tried multiple ways.  I can get it to run successful but no attachment to DevOps, or I'll get an error about patching not passing through.  

 

I've also tried to add another http request and doing a POST and URI is "/project/_apis/wit/attachments?api-version=6.0" and nothing else.  It didn't work.

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    v-xiaochen-msft Profile Picture
    Microsoft Employee on at
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I didn't do the "Create Work Item" because the limitation if the task/work item would show it was created by me (owner of the flow).  It would get confusing for us if it showed I was the creator of every work item and the only way we could see who submitted the form is the backend of MS Forms or Power Automate, or request an email to display (which is an issue also).  I needed each task to show who submitted a form for a request, and it tag specific people in the discussion upon creation so it would send an email out.

     

    Skipping the "Create a work item" and passing all the information from MS Forms to a "send http request to azure devops" and using JSON allowed me to fix that.  The issue with this way is I cannot see or grab the "ID" of the work item once its created from the JSON data using the request, so I can't update "work item".

  • NiclasWJ Profile Picture
    19 on at

    EDIT:
    Below only worked if an attachment was actually uploaded but failed if no upload was made.
    To fix this, we add a condition based on length on the actual form output that we are using and put the "Parse JSON" and "For Each Attachment" within that "If yes".

     

    The condition should be " "0" is not equal to "length(body('Get_response_details')?['the_form_question'])" "

     

    NiclasWJ_0-1698997766900.png

     

     

     

    Hi @Anonymous 

    I dont know if this solves your issues but I will give it a try.
    Recently I managed to get my upload working and since I do not see this "solution" elsewhere in the community I thought of posting it.
    This solution adds ALL attachments for me.

     

    I am no Power Automate veteran so have that in mind, and sorry in advance for the mix of Swedish and English in the samples below.

    NiclasWJ_0-1698658235643.png

    NiclasWJ_1-1698658235645.png

    NiclasWJ_2-1698658235645.png

     

    Explanation:

    1. "Parse the JSON" with the question including the upload attachment from the MS Forms "Get Response Details"

    Scheme:

     

    {
     "type": "array",
     "items": {
     "type": "object",
     "properties": {
     "name": {
     "type": "string"
     },
     "link": {
     "type": "string"
     },
     "id": {
     "type": "string"
     },
     "type": {},
     "size": {
     "type": "integer"
     },
     "referenceId": {
     "type": "string"
     },
     "driveId": {
     "type": "string"
     },
     "status": {
     "type": "integer"
     },
     "uploadSessionUrl": {}
     },
     "required": [
     "name",
     "link",
     "id",
     "type",
     "size",
     "referenceId",
     "driveId",
     "status",
     "uploadSessionUrl"
     ]
     }
    }

     

    2. "For Each" I then:

    3. "OneDrive for Business - Get File Content by Path" where the content is the path such as apps/Microsoft Forms/{form name}/{question}/@{items('For_Each_Attachment')['name']} - This to get the content of all files as Base64, Name is from the first Parse JSON

    4. "Compose" with the expression below - This is to retrieve only the Base64 content from the Get File Content which contains other information as well.

     

    outputs('Get_File_Content_by_Path')?['body/$content']

     


    5. "Send a HTTP request to Azure DevOps - Send Attachment to DevOps" with:

    POST

    URL = {project}/_apis/wit/attachments?filename=@{items('For_Each_Attachment')['name']}&api-version=7.1

    Content-Type = application/octet-stream

    Body = Output of "Compose"

    Set body as Base64

    This is to send the attachment into DevOps, this does not link it to any workitem. Name is from the first Parse JSON.

    6. "Parse JSON" with the output from "Send Attachment to DevOps" as content and the following scheme:

     

    {
     "type": "object",
     "properties": {
     "id": {
     "type": "string"
     },
     "url": {
     "type": "string"
     }
     }
    }

     

    This is so we can know what the URL is of the attachment we want to attach later on.

     

    7. "Send a HTTP request to Azure DevOps - Add attachment" with:

    PATCH

    URL = {project}/_apis/wit/workitems/@{outputs('Create_change_request')?['body/id']}/?api-version=7.2-preview

    @{outputs('Create_change_request')?['body/id']} is the ID of your workitem which is created before in the flow

    Content-Type = application/json-patch+json

    Body = ( url = "url" from lst Parse JSON ) ( name = name from first Parse JSON )

     

    [
    {
    "op": "add",
    "path": "/relations/-",
    "value":
    {
    "rel": "AttachedFile",
    "url": "@{body('Parsa_JSON_2')?['url']}",
    "attributes": 
    {
    "comment": "Automatic attachment upload",
    "name":"@{items('For_Each_Attachment')['name']}"
    }
    }
    }
    ]

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 250 Super User 2026 Season 1

#2
Expiscornovus Profile Picture

Expiscornovus 222 Most Valuable Professional

#3
Haque Profile Picture

Haque 174

Last 30 days Overall leaderboard