cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaifAli
Helper III
Helper III

Adding the attachments to Azure DevOps work item in "Create a Work item" step

Hi ,

 

Is there a way to attach a certain file from email directly to the attachments section in the User story of Azure DevOps, I'm currently having a flow that creates a work item whenever tehre is a new email but can't able to process the attachments linked to it. I need those attachments in the user story itself. Can somebody help me??

54 REPLIES 54

Hi @SaifAli 

 

Currently adding an attachment as a direct action is not supported in flow. However, you can refer to the thread below where a workaround has been suggested for creating the attachments:

https://powerusers.microsoft.com/t5/Building-Flows/Create-work-item-at-Azure-DevOps-from-an-email-wi...

 

You can post an idea here to include this as a feature in flow:

https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

TheSwilliam
Frequent Visitor

Make sure you name everything the exact same thing as what I have if you are copying and pasting from here. You will need to add in your organization name.

The schema is:

First part flow.PNG

 

 

{
    "type": "object",
    "properties": {
        "Id": {
            "type": "string"
        },
        "Name": {
            "type": "string"
        },
        "ContentBytes": {
            "type": "string"
        },
        "ContentType": {
            "type": "string"
        },
        "Size": {
            "type": "integer"
        }
    }
}

 

 

 

Then

Post the attachment.PNG

the binary function is: 

 

 

 

binary(body('Parse_JSON')?['ContentBytes'])

 

 

 

Make sure you change the areaPath in the relative URI. I left it as mine which is just Portal.
Code snippet for the step above: 
{
    "inputs": {
        "host": {
            "connection": {
                "name""@parameters('$connections')['shared_visualstudioteamservices']['connectionId']"
            }
        },
        "method""post",
        "body": {
            "Method""POST",
            "Headers": {
                "Content-Type""application/octet-stream"
            },
            "Body""@{binary(body('Parse_JSON')?['ContentBytes'])}",
            "IsBase64"true
        },
        "path""/httprequest",
        "queries": {
            "account""YourOrganization"
        },
        "authentication""@parameters('$authentication')"
    },
    "metadata": {
        "flowSystemMetadata": {
            "swaggerOperationId""HttpRequest"
        }
    }
}
Then
compose.PNG
The 'Body' in 'Compose' is the body that you will get from the Http Post which I have named 'Post Attachment'
The 'url' is actually an output function: 

 

 

 

outputs('Compose')['url']

 

 

 

The outputs function is getting the url property from the response json from Post Attachment.
Code snippets for the steps above:
Compose:
{
    "inputs""@body('Post_Attachment')"
}
Compose 2
{
    "inputs""@outputs('Compose')['url']"
}
 

Then

Final 3.PNG
The 'Id' is the work Item Id that gets returned form the create a new work item step. 
The 'Outputs' is from 'Compose2'. It should pop up for you on the add dynamic content popup.  
Code snippet for the step above:
{
    "inputs": {
        "host": {
            "connection": {
                "name""@parameters('$connections')['shared_visualstudioteamservices']['connectionId']"
            }
        },
        "method""post",
        "body": {
            "Method""PATCH",
            "Headers": {
                "Content-Type""application/json-patch+json"
            },
            "Body""[\n  {\n    \"op\": \"add\",\n    \"path\": \"/relations/-\",\n    \"value\": {\n      \"rel\": \"AttachedFile\",\n      \"url\": \"@{outputs('Compose_2')}\",\n      \"attributes\": {\n        \"comment\": \"Spec for the work\"\n      }\n    }\n  }\n]",
            "IsBase64"false
        },
        "path""/httprequest",
        "queries": {
            "account""YourOrganization"
        },
        "authentication""@parameters('$authentication')"
    },
    "metadata": {
        "flowSystemMetadata": {
            "swaggerOperationId""HttpRequest"
        }
    }
}

 

 

Hope this helps!

Make sure you name everything the exact same thing as what I have if you are copying and pasting from here. You will need to add in your organization name.

First part flow.PNG

The schema is:

 

{
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Name": {
"type": "string"
},
"ContentBytes": {
"type": "string"
},
"ContentType": {
"type": "string"
},
"Size": {
"type": "integer"
}
}
}

 

Then
Post the attachment.PNG
the binary function is: 

 

binary(body('Parse_JSON')?['ContentBytes'])

 

Make sure you change the areaPath in the relative URI. I left it as mine which is just Portal.
 
Then
compose.PNG
The 'Body' in 'Compose' is the body that you will get from the Http Post which I have named 'Post Attachment'
The 'url' is actually an output function: 

 

outputs('Compose')['url']

 

The outputs function is getting the url property from the response json from Post Attachment.
 
Then
Final 3.PNG
The 'Id' is the work Item Id that gets returned form the create a new work item step. 
The 'Outputs' is from 'Compose2'. It should pop up for you on the add dynamic content popup.  

Hope this helps!

Anonymous
Not applicable

@TheSwilliam 

Thank you for the solution. I implemented your solution and the flow did run successfully, but the file wasn't attached to the work item in Azure DevOps. Can you please advise?

Hi @Anonymous,

 

Can you send screen shots of your two Http request actions? You have to make sure the first is a POST with the header "Content-Type""application/octet-stream". The second one has to be a PATCH with the header  "Content-Type": "application/json-patch+json" 

Anonymous
Not applicable

@TheSwilliam 

Thank you for your quick response.

Please find attached the screenshots:

johns4Upmc_0-1599074442994.png

 

 

johns4Upmc_1-1599074584001.png

 

@Anonymous everything looks good there. Do you mind sending the binary function and the compose functions. You can just send the code. Also what type of files are you sending/how big are they? You may need to change your upload type from simple to chunked. Here is the link if you'd like to read about it. 

https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/attachments/create?view=azure-devops-rest-6.0#start-a-chunked-upload

Anonymous
Not applicable

@TheSwilliam 

 

johns4Upmc_0-1599075680979.png

Binary Function : 

binary(body('Parse_JSON')?['ContentBytes'])
Anonymous
Not applicable

@TheSwilliam The file is a normal .txt or .pdf file

@Anonymous I see your issue. You are grabbing the wrong body in your first compose. You need to grab the body that the first http request generates. 

Anonymous
Not applicable

Thank you @TheSwilliam. I did update the body part, but still the files are not getting attached. 

@Anonymous  I think you are also grabbing the wrong thing in your compose2. When you peak at the code this is what you should see in your compose 2:

outputs('Compose')['url'])

Anonymous
Not applicable

@TheSwilliam 

Thank you so much. I was able to attach the file to the Work Item in Azure DevOps.

Is there any reason why Post Attachment isn't an option for me? I'm just using the pro trial right now, but is it possible our instance of Azure Devops might be limiting functionality in some way?

Anonymous
Not applicable

@jbwharris I believe you would need Azure DevOps Premium connector to implement this functionality.

@jbwharris I renamed the ‘send an http request to azure devops’ action to ‘Post Attachment’ that’s why it isn’t showing up for you. Just use send an http request to azure devops and you’ll be good 

Nice solution and worked flawlessly for my flow.

Thanks!

Great tutorial,  I'm getting error and i have tried everything not sure why i'm getting it as followed the instructions closely:

You must pass a valid patch document in the body of the request.  I am testing with a .xlsx
Azure DevOps ActivityId: 4bbf592f-9f6d-4b1b-9b37-64c3fab79e50
Details: {"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
clientRequestId: eaa606b1-3ae9-4041-8b18-27309ce4f369

Here is what i have in the body:

[
{
"op:"add",
"path":"/relations/-",
"value":{
"rel":"AttachedFile",
"url":"@{outputs('Compose_2')}",
"attributes":{
"comment":"Adding attachments"
}
}
}
]

 

Any help would be appreciated it. 

Great tutorial,  I'm getting error and i have tried everything not sure why i'm getting it as followed the instructions closely:

You must pass a valid patch document in the body of the request.  I am testing with a .xlsx
Azure DevOps ActivityId: 4bbf592f-9f6d-4b1b-9b37-64c3fab79e50
Details: {"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
clientRequestId: eaa606b1-3ae9-4041-8b18-27309ce4f369

Here is what i have in the body:

[
{
"op:"add",
"path":"/relations/-",
"value":{
"rel":"AttachedFile",
"url":"@{outputs('Compose_2')}",
"attributes":{
"comment":"Adding attachments"
}
}
}
]

 

Any help would be appreciated it. 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (7,961)