cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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

64 REPLIES 64
yashag2255
Super User
Super User

Hi @Anonymous 

 

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-with-attachments/td-p/176019

 

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

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (6,414)