cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Create/ Update a query in Azure DevOps with flow

Hello Everyone!

 

As we do not have an action to create/ update a query in Azure DevOps, we can use the "Send HTTP Request to Azure DevOps function" to create or to update an already existing query. 

 

Please have a look at the screenshot below:

 

azdevflow.png

 

I have used the "When a work item is assigned" trigger for the flow. In the next step I am updating an already created query (TestNew) by sending a PATCH HTTP Request. Please note that if you want to create a new query, all you have to do is remove the query name from the URI, leave the folder name in that place and change the request from PATCH to POST. I am updating the query to get the work item and its related work items based on the ID retrieved from the trigger. 

 

Body: {
"name" : "TestNew",
"queryType" : "tree",
"wiql" : "SELECT [System.Id],[System.Title],[System.State] FROM workitemLinks WHERE([Source].[System.WorkItemType] = 'Task' AND [Source].[System.Id] = @{triggerBody()?['id']})AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')AND ([Target].[System.WorkItemType] = 'Task')MODE (Recursive)"
}

Ensure that you you correctly format the "wiql" as this is the actual query that will fetch the results. The next action is to get the ID of the updated/ new query and I did that using the initialise string variable and expression:

body('Send_an_HTTP_request_to_Azure_DevOps')['id']

Finally in the screenshot you can see that I used the "Get Query Results" action to fetch the query from Azure DevOps. This returns a JSON with all the details as requested through the "wiql" query. 

 

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!

 

8 REPLIES 8
v-bram
Level: Powered On

Re: Create/ Update a query in Azure DevOps with flow

Hi yashag2255, nice article!  Since you have successfully used the Action "Send an HTTP request to Azure DevOps", can you help me successfully get the JSON that I am requesting?
 
Right now, any Azure DevOps HTTP call that I build produces the html page to login instead of getting JSON. I get this behavior in MS Flow and Postman.

login.png

I can successfully make the call in Edge and Chrome (once I login in with my credentials) and get my JSON data.

 

 

Example web calls looks like this:

GET https://dev.azure.com/microsoft/os/WDGIS/_apis/wit/wiql/8f5dc074-69fa-4d2c-ba9e-xxxxxxxxxx?api-versi...

GET https://dev.azure.com/microsoft/OS/_apis/wit/queries/8f5dc074-69fa-4d2c-ba9e-xxxxxxxxx?api-version=5...

 

I do realize that this has to do with my credentials.  In Flow, I have tried switching the account on the Azure DevOps connection.  The popup displays, gives me an "hourglass" to determine my accounts and then vanishes.  My guess is that I don't have multiple accounts. Also, I have deleted this connection and recreated it. Same results...

 

I believe my Azure DevOps connection is fine.  Below is an example where I can successfully Get the Work Item details successfully and then fail to login with the HTTP request???  Any idea on how i can get this Action to work?

AzureDevOps.pngADO1.pngADO2.png

 

Super User
Super User

Re: Create/ Update a query in Azure DevOps with flow

Hi @v-bram 

 

Can you please share more details on this? (I am unable to view the samples from the URLs you shared due to the organisation limitation). 

 

Based on the screenshot, I can see that you are missing a paranthesis close '}' at the end of the body in the action 'Send HTTP Request to azure devops'. 

 

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!

v-bram
Level: Powered On

Re: Create/ Update a query in Azure DevOps with flow

Hi @yashag2255 ,

Thank you for the fast response!  Good catch on missing the "{"!  Unfortunately, I still get the same error Smiley Sad

Sorry, unable to insert a picture.  Just for edification, here is my JSON structure now:

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

 

I am still getting the login html in Flow (instead of the JSON data).  What more evidence can I provide you?  I can show you the data that I get back in Edge?  I have also attempted creating a personalToken.  I created it successfully and tried to place the key (the one you have to copy when it is generated only) in the Rest call.  Suggestions?

Thank you,

@v-bram 

v-bram
Level: Powered On

Re: Create/ Update a query in Azure DevOps with flow

@yashag2255 

 

I figured out the solution.  I have now have Postman and Powershell calling the WebRequest correctly using basic authentication using a Personal Token.  As for Flow, I was unable to use the Azure DevOps Send HTTP WebRequest Action using basic auth.  Instead I am using the regular HTTP action since that functionality exists in there.  Thank you for your help!

 

@v-bram 

Super User
Super User

Re: Create/ Update a query in Azure DevOps with flow

@v-bram 

 

Glad that you were able to make it work with the send HTTP request action. It should also work with the Azure DevOps Http request action too. In case you work on that later and get stuck sonewhere/ find a solution please keep us posted. 

SaifAli
Level: Powered On

Re: Create/ Update a query in Azure DevOps with flow

Hi @v-bram 

 

Can you please share the screenshot of the HTTP request method ? I've created the Personal access token but still not getting any successSmiley Sad , I'm stuck on this for so long. It'll be really helpful

v-bram
Level: Powered On

Re: Create/ Update a query in Azure DevOps with flow

To @SaifAli 

 

I am sorry you have struggled a while.  I know how that feels.  Above I did show the HTTP call. However, I didn't show the Authentication part.  Pick the following advanced properties in the HTTP Action in Flow:

 

Authentication: Basic

Username: <your username for the personal token>

Password: <your password generated by Microsoft for the token which is given to you only once>

 

When I applied this authentication, I was able to run my HTTP call through Flow, Postman, PowerShell, etc.

 

If you need further help, you will need to show the HTTP call.

 

Hope this helps!

@v-bram 

SaifAli
Level: Powered On

Re: Create/ Update a query in Azure DevOps with flow

Thanks @v-bram ,

 

It worked in the flow, Don't know why but the same isn't working in Postman, but as long as it is working in Flow its good for me thank you.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 379 members 5,558 guests
Please welcome our newest community members: