Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
HamletDRC
Employee
Employee

Loading data via REST API - query dependent API (parent/child calls)

I am using Power BI to read data from the Azure DevOps REST API. 

 

I want to use PowerQuery to get the pull requests in the ADO instance, and the comment threads associated with this pull requests. Doing this in a traditional programming language would be a 2 step process: 

  1. Get the list of pull requests using HTTP GET: https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/get%20pull%20requests?vie...
  2. For-each item in the result set, get the comment threads using the HTTP GET: https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20request%20threads/list?view=azure-...

The URL to load the comment threads is: 
https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{p...

 

I need to somehow query the /threads endpoint and fill in a {pullRequestId} parameter. 

 

Ideally I'd like two takes to show up in Power BI: one for the pull requests and one for the threads. 

1 ACCEPTED SOLUTION
HamletDRC
Employee
Employee

I found a solution. At a high level: 

  1. Define a "Pull Requests" table that queries the parent REST API. Put the pull request ID in a column named pullRequestId
  2. Define a function that queries the child REST API taking the pullRequestId as a parameter, returning a single List value
  3. Create a table filled with the primary key value and a blank column to hold the list
  4. Fill the blank column with the results of the function call. 

 

Specifically, my function definition is: 

 

let
Source = (pullRequestId) => let
Source2 = Json.Document(Web.Contents(Text.Combine({"https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repoName}/pullRequests/", Text.From(pullRequestId), "/threads?api-version=6.1-preview.1"}))),
#"Converted to Table" = Table.FromRecords({Source2}),
#"Removed Columns" = Table.RemoveColumns(#"Converted to Table",{"count"})
in
#"Removed Columns"
in
Source

And my table definition is: 

let
Source = Table.SelectColumns( #"Pull Requests" , "value.pullRequestId"),
#"Renamed Columns" = Table.RenameColumns(Source,{{"value.pullRequestId", "pullRequestId"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "value", each GetPrThread([pullRequestId]))
in
#"Added Custom"

From there you just use Power BI to expand columns as you need. 

View solution in original post

2 REPLIES 2
HamletDRC
Employee
Employee

I found a solution. At a high level: 

  1. Define a "Pull Requests" table that queries the parent REST API. Put the pull request ID in a column named pullRequestId
  2. Define a function that queries the child REST API taking the pullRequestId as a parameter, returning a single List value
  3. Create a table filled with the primary key value and a blank column to hold the list
  4. Fill the blank column with the results of the function call. 

 

Specifically, my function definition is: 

 

let
Source = (pullRequestId) => let
Source2 = Json.Document(Web.Contents(Text.Combine({"https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repoName}/pullRequests/", Text.From(pullRequestId), "/threads?api-version=6.1-preview.1"}))),
#"Converted to Table" = Table.FromRecords({Source2}),
#"Removed Columns" = Table.RemoveColumns(#"Converted to Table",{"count"})
in
#"Removed Columns"
in
Source

And my table definition is: 

let
Source = Table.SelectColumns( #"Pull Requests" , "value.pullRequestId"),
#"Renamed Columns" = Table.RenameColumns(Source,{{"value.pullRequestId", "pullRequestId"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "value", each GetPrThread([pullRequestId]))
in
#"Added Custom"

From there you just use Power BI to expand columns as you need. 

v-stephen-msft
Community Support
Community Support

Hi @HamletDRC ,

 

I found these similar posts which might be helpful:

Using a REST API as a data source

How to Easily Get Data from Web Source Using Power BI Rest API Calls

Importing data from JSON files and Power BI Rest APIs into Power BI

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors