1

I am starting to use PowerShell to call the Azure DevOps REST API. But it seems like when I try to add parameters it tell me:

A parameter cannot be found that matches parameter name 'repositoryId'

Here is what my call looks like in PowerShell. If I take out the parameter it works. What am I doing wrong?

Invoke-RestMethod -Uri 'https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.1' -repositoryId $repoId -Headers (my authentication) -Method Get

Per Microsoft's documentation this should work. https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-5.1

2 Answers 2

2

repositoryId should be url parameter as Booga Roo mentioned. The error indicated that Repository type is missing.

You should add another parameter to your uri repositoryType={repositoryType}.So the uri should be like below.

Please check here for all repositoryTypes

https://dev.azure.com/{Organization}/{Project}/_apis/build/builds?repositoryId={id}&repositoryType=TfsGit&api-version=5.1

Addition:

You can get your repositoryId from URL of Repositories page under Repos in the Project Settings. Check below screentshot.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

The Invoke-RestMethod cmdlet does not have a -repositoryId parameter. The phrasing and examples on the help page are for "URI Parameters" instead of PowerShell parameters. It means you need to build it into -Uri value instead of trying to use it directly.

I suggest using this:

Invoke-RestMethod -Uri "https://dev.azure.com/{organization}/{project}/_apis/build/builds?repositoryId={$repoId}&api-version=5.1" -Headers (my authentication) -Method Get

Side note: There are double quotes around this example URI. This is so the variable expansion for $repoId will occur and be properly interpreted as part of the URI. Using single quotes as in the original example will prevent this and treat it as a literal string value and won't perform any subsitutions.

4 Comments

I tried what you suggested and that is what I initial tried but I get "Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Repository type is missing/invalid.","typeName":"Microsoft.TeamFoundation.Build.WebApi.RepositoryInformationInvalidException, Microsoft.TeamFoundation.Build2.WebApi","typeKey":"RepositoryInformationInvalidException","errorCode":0,"eventId":3000}"
I don't have an instance to test against a the moment, but I would expect that means that the repo ID is either incorrect, mis-formatted, unexpanded, missing, or you don't have permissions to that particular repo. However, since you said it works without using the parameter, I would imagine you do have permissions. So, if you check the value of $repoId does it return what you expected?
@Nathan There was also a missing ampersand in the URI example above. Hopefully you noticed, but it has been updated to add that in the example.
Thank you for all the help. It seems putting quotes around my RepositoryType was my problem. It is now not throwing errors and showing me results I expect. Thank you all for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.