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
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.
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.
Related
I am running this code and its not returning the data to my $response variable as I expected.
$targetUrl = "https://www.tigerrunresort.com/vacation-rentals-homes-search.asp?txtStartDate=8%2F1%2F2022&txtEndDate=8%2F7%2F2022&categoryid=11317&destinationID=0&communityID=0&amenBedrooms=-1&maxPersons=0&advs=&sort=0¤tPage=1&flexibleDates=0&flexibleDatesThreshold=&searchAmenities=&showOnlySpecials=0"
$Response = Invoke-WebRequest -Uri $targetUrl
In rawcontent I should expect to see the string "Sorry" which does not show. What do I need to do to get it to return the values as I would see interactively?
Thanks!
You are not seeing it because it is not actually in the response. It is probably created and appended to the DOM by Javascript. Due to the Invoke-WebRequest not executing Javascript, it is never part of the response. If you are looking to orchestrate browsers (which do execute Javascript and offer access to the DOM) maybe you can try taking a look at Selenium (https://www.selenium.dev/)
For lauching a web request you can use for example start-process like this : start-process microsoft-edge:http://google.com/
I have the following Powershell script that runs without issue. I am being told that I need to add "&onlyCurrent=false" to get it to pull information for employees with a future start date. I have no idea how to do this....
$response = Invoke-RestMethod 'https://api._________.com/api/gateway.php/gemco/v1/reports/120' -Method 'GET' -Headers $headers
When I add this to the end, I get invalid parameter error message:
-Where-Object onlyCurrent eq "false"
The support for they system I'm pulling this from has no information on how to do this. Absolutely any help would be very greatly appreciated.
&onlyCurrent=false is probably a query string. You can append it at the end of the URL after ?. Note that & is used to separate multiple parameters, since you have just one it's not needed. Try changing the URL to:
https://api._________.com/api/gateway.php/gemco/v1/reports/120?onlyCurrent=false
Figured it out. You have to add ?onlyCurrent=false after the 120 (inside the single quote).
I'm using query string parameters in a Graph API request to fetch users from Azure AD, however none appear to be working when I execute it through Powershell.
Here's the documentation on the API: https://learn.microsoft.com/en-us/graph/query-parameters
Here's some details about the scenario:
The request: https://graph.microsoft.com/v1.0/users?$top=999&$select=userPrincipalName
Executed via Powershell using the Invoke-RestMethod command
It seems to work when I use the Graph Explorer: https://developer.microsoft.com/en-us/graph/graph-explorer
I assume your app registration is set up properly and you have given the appropriate permissions etc. got the token and make the restmethod call, and the call returns full user profiles and not just the upn. It would be helpful if you provided some code. Assuming the above, from the little additional info, probably powershell is replacing your $top and $select with blank or something, because it will likely treat those as powershell variables instead of literally put them in the request url. meaning you probably did something like invoke-restmethod -Uri "graphurl?$top=etcetc" change that to single quote to take the literal string eg. invoke-restmethod -Uri 'graphurl?$top=etcetc'
I have an MS Graph API in PowerShell working for the most part.
I am using
$Uri = $null
$Uri = "https://graph.microsoft.com/v1.0/users?$select=displayName,givenName,postalCode"
$payload=$null
$payload = Invoke-RestMethod -uri $Uri -Headers $Header -Method Get -ContentType "application/json"
$payload.value
however, it is not changing the field selection. It keeps returning the default fields as demonstrated here
https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http
What could I possibly be doing wrong?
I am using application based authentication. The payload is being returned but it is not recognizing the $select statement.
No errors are being returned by the PowerShell
I run it in Graph Explorer it works fine.
The error is caused by the type of string declaration used for the Uri string. You are declaring the string like this:
$Uri = "https://graph.microsoft.com/v1.0/users?$select=displayName,givenName,postalCode"
This tells Powershell, that you want to evaluate the string. $ is Powershell's variable identifier. Undeclared variables are set automatically to an empty string, when evaluated in a string. Therefore the request executed against the Graph Api is:
https://graph.microsoft.com/v1.0/users?=displayName,givenName,postalCode
Your can check this yourself by writing the variable to the host:
Write-Host $Uri
If you execute this query with the Graph Explorer. It will return all users without an applied filter, which is the behaviour you have observed. You need to change the declaration to:
$Uri = 'https://graph.microsoft.com/v1.0/users?$select=displayName,givenName,postalCode'
Then, Powershell will not interpret $select as a variable and your request should work properly.
I'm interfacing with an API with PowerShell Invoke-RestMethod cmdlet.
One of the API endpoints requires the method "Link", however this method is not supported by Invoke-RestMethod.
With CURL it is working fine
Is there a way around this?
Error message:
Invoke-RestMethod : Cannot bind parameter 'Method'. Cannot convert value "LINK" to type "Microsoft.PowerShell.Commands.WebRequestMethod". Error: "Unable to match the identifier name LINK to a valid enumerator name. Specify one of the following enumerator names and try again:
Default, Get, Head, Post, Put, Delete, Trace, Options, Merge, Patch
In PowerShell v6+, Invoke-WebRequest has a parameter CustomMethod.
This can be used with the Request Method required by the endpoint is not an available option on the -Method.
Look at the MS documentation on how to use custom method in invoke-webrequest
Update
You can use .Net class WebRequest to send your request as follows, and this will work on any PowerShell version:
$req = [net.webrequest]::create('https://www.google.com')
$req.Method = 'LINK'
$resp = $req.GetResponse()
Look here for further information