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??

63 REPLIES 63

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
Advocate I
Advocate I

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.

Anonymous
Not applicable

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

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

@Anonymous 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 Platform Connections - Episode 7 | March 30, 2023

Episode Seven of Power Platform Connections sees David Warner and Hugo Bernier talk to Dian Taylor, alongside the latest news, product reviews, and community blogs.     Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show.  

Announcing | Super Users - 2023 Season 1

Super Users – 2023 Season 1    We are excited to kick off the Power Users Super User Program for 2023 - Season 1.  The Power Platform Super Users have done an amazing job in keeping the Power Platform communities helpful, accurate and responsive. We would like to send these amazing folks a big THANK YOU for their efforts.      Super User Season 1 | Contributions July 1, 2022 – December 31, 2022  Super User Season 2 | Contributions January 1, 2023 – June 30, 2023    Curious what a Super User is? Super Users are especially active community members who are eager to help others with their community questions. There are 2 Super User seasons in a year, and we monitor the community for new potential Super Users at the end of each season. Super Users are recognized in the community with both a rank name and icon next to their username, and a seasonal badge on their profile.  Power Apps  Power Automate  Power Virtual Agents  Power Pages  Pstork1*  Pstork1*  Pstork1*  OliverRodrigues  BCBuizer  Expiscornovus*  Expiscornovus*  ragavanrajan  AhmedSalih  grantjenkins  renatoromao    Mira_Ghaly*  Mira_Ghaly*      Sundeep_Malik*  Sundeep_Malik*      SudeepGhatakNZ*  SudeepGhatakNZ*      StretchFredrik*  StretchFredrik*      365-Assist*  365-Assist*      cha_cha  ekarim2020      timl  Hardesh15      iAm_ManCat  annajhaveri      SebS  Rhiassuring      LaurensM  abm      TheRobRush  Ankesh_49      WiZey  lbendlin      Nogueira1306  Kaif_Siddique      victorcp  RobElliott      dpoggemann  srduval      SBax  CFernandes      Roverandom  schwibach      Akser  CraigStewart      PowerRanger  MichaelAnnis      subsguts  David_MA      EricRegnier  edgonzales      zmansuri  GeorgiosG      ChrisPiasecki  ryule      AmDev  fchopo      phipps0218  tom_riha      theapurva  takolota     Akash17  momlo     BCLS776  Shuvam-rpa     rampprakash  ScottShearer     Rusk  ChristianAbata     cchannon  Koen5     a33ik  Heartholme     AaronKnox  okeks      Matren   David_MA     Alex_10        Jeff_Thorpe        poweractivate        Ramole        DianaBirkelbach        DavidZoon        AJ_Z        PriyankaGeethik        BrianS        StalinPonnusamy        HamidBee        CNT        Anonymous_Hippo        Anchov        KeithAtherton        alaabitar        Tolu_Victor        KRider        sperry1625        IPC_ahaas      zuurg    rubin_boer   cwebb365   Dorrinda   G1124   Gabibalaban   Manan-Malhotra   jcfDaniel   WarrenBelz   Waegemma   drrickryp   GuidoPreite    If an * is at the end of a user's name this means they are a Multi Super User, in more than one community. Please note this is not the final list, as we are pending a few acceptances.  Once they are received the list will be updated. 

Register now for the Business Applications Launch Event | Tuesday, April 4, 2023

Join us for an in-depth look into the latest updates across Microsoft Dynamics 365 and Microsoft Power Platform that are helping businesses overcome their biggest challenges today.   Find out about new features, capabilities, and best practices for connecting data to deliver exceptional customer experiences, collaborating, and creating using AI-powered capabilities, driving productivity with automation—and building towards future growth with today’s leading technology.   Microsoft leaders and experts will guide you through the full 2023 release wave 1 and how these advancements will help you: Expand visibility, reduce time, and enhance creativity in your departments and teams with unified, AI-powered capabilities.Empower your employees to focus on revenue-generating tasks while automating repetitive tasks.Connect people, data, and processes across your organization with modern collaboration tools.Innovate without limits using the latest in low-code development, including new GPT-powered capabilities.    Click Here to Register Today!    

Check out the new Power Platform Communities Front Door Experience!

We are excited to share the ‘Power Platform Communities Front Door’ experience with you!   Front Door brings together content from all the Power Platform communities into a single place for our community members, customers and low-code, no-code enthusiasts to learn, share and engage with peers, advocates, community program managers and our product team members. There are a host of features and new capabilities now available on Power Platform Communities Front Door to make content more discoverable for all power product community users which includes ForumsUser GroupsEventsCommunity highlightsCommunity by numbersLinks to all communities Users can see top discussions from across all the Power Platform communities and easily navigate to the latest or trending posts for further interaction. Additionally, they can filter to individual products as well.   Users can filter and browse the user group events from all power platform products with feature parity to existing community user group experience and added filtering capabilities.     Users can now explore user groups on the Power Platform Front Door landing page with capability to view all products in Power Platform.      Explore Power Platform Communities Front Door today. Visit Power Platform Community Front door to easily navigate to the different product communities, view a roll up of user groups, events and forums.

Microsoft Power Platform Conference | Registration Open | Oct. 3-5 2023

We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5 2023! But first, let's take a look back at some fun moments and the best community in tech from MPPC 2022 in Orlando, Florida.   Featuring guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, Stephen Siciliano, Hugo Bernier and many more.   Register today: https://www.powerplatformconf.com/   

Users online (3,489)