SOLVED

AzDO API not returning more than 100 results

Copper Contributor

I am trying to get releases from my Project using the API. However, I am no able to get more than 100 results.

$top doesn't seem to work over 100? Is there a way to get more than 100 releases?

5 Replies
best response confirmed by abhi433 (Copper Contributor)
Solution

@abhi433 

Hi, I'm not sure whether you are already using "x-ms-continuation-token" to fetch all the records. Please take a look at Accessing Azure DevOps APIs with large volumes of data (jessehouwing.net) for usage reference.

 

Please mark my answer as "Best Response" if it solves your problem.

 

Regards

Raviraj

releases = session.get(f'https://vsrm.dev.azure.com/{org}/{project}/_apis/release/releases?api-version=6.1-preview.8&$top=100...)
rel_list = releases.json()['value']
for rel in rel_list:
rel_id = rel['id']
reles_list.append(rel_id)
if 'x-ms-continuationtoken' in releases.headers:
token = releases.headers['x-ms-continuationtoken']
next_releases = session.get(f'https://vsrm.dev.azure.com/{org}/{project}/_apis/release/releases?api-version=6.1-preview.8&$top=100...)
n_rel_list = next_releases.json()['value']
for n_rel in n_rel_list:
n_rel_id = n_rel['id']
reles_list.append(n_rel_id)
I did that. However, when I put it in a while loop, I saw that the token was returned everytime...so, for now I am just running the loop twice. Not a solution, though.

@abhi433 

Thanks for updating the latest code you are using.

Did you configured "continuationToken" header while running inside the while loop? I don't see that logic in your code.

if ($headers["x-ms-continuationtoken"])
    {
        $continuation = $headers["x-ms-continuationtoken"]
        write-host "Token: $continuation"
        $url = $urlBase + "&continuationToken=" + $continuation
    }

In the above code, continuationToken is set in line number 5 to fetch the records for next iteration.

 

Regards

Raviraj

 

As I mentioned, it was being returned everytime. So, I had to let go of it.

@Raviraj_Nallasivam 

Hello, i tried with your response but it is getting failure.


$User=""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,$AzureDevOpsPAT)))
$token = @{Authorization=("Basic {0}" -f $base64AuthInfo)}

# Get pipelines
$pipelines = "https://vsrm.dev.azure.com/$OrganizationName/$Project/_apis/release/releases?api-version=7.0&path=$folder&minCreatedTime=$minCreatedTime&maxCreatedTime=$maxCreatedTime&`$top=$count"
$outputreport = @()
$users =@()
$results = @();

do
{
    write-host "Calling API"
    $totalpipeline = Invoke-RestMethod -Uri $pipelines -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
    $results += $totalpipeline.value
    if ($headers["x-ms-continuationtoken"])
    {
        $continuation = $headers["x-ms-continuationtoken"]
        write-host "Token: $continuation"
        $url = $urlBase + "&continuationToken=" + $continuation
    }
} while ($headers["x-ms-continuationtoken"])

$results
 
Error: 

Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'.
At C:\Users\****\powershell_script\Pipeline_report\pipeline_report.ps1:32 char:22
+ ... lpipeline = Invoke-RestMethod -Uri $pipelines -Headers @{Authorizatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
1 best response

Accepted Solutions
best response confirmed by abhi433 (Copper Contributor)
Solution

@abhi433 

Hi, I'm not sure whether you are already using "x-ms-continuation-token" to fetch all the records. Please take a look at Accessing Azure DevOps APIs with large volumes of data (jessehouwing.net) for usage reference.

 

Please mark my answer as "Best Response" if it solves your problem.

 

Regards

Raviraj

View solution in original post