Questions tagged [invoke-restmethod]
129 questions
20
votes
3 answers
Powershell Invoke-RestMethod Authorization Header
While invoking an Invoke-RestMethod using Powershell like:
Invoke-RestMethod -Method Get -Uri "https://google.com/api/GetData" -Headers $headers
and $headers being
$headers = @{
Authorization="Secret $username $password"
…

Reddipalle Nagarjun
- 253
- 1
- 4
- 9
9
votes
1 answer
Invoke-RestMethod hangs on long running endpoints
We are using Invoke-RestMethod in a PowerShell script to call a GET method endpoint with a variable length runtime. Some calls may return after a couple of seconds, some may take up to 20 minutes. We've set a 50 minute timeout on the call via the…

Ryan B
- 848
- 6
- 9
4
votes
0 answers
Invoke-RestMethod automatically converts UTC date strings using PowerShell 7.x
I'm testing an existing PowerShell module that uses a third party REST API. With PowerShell 5.1, the module correctly returns json with an embedded date string in UTC format, as expected. However, when using PowerShell 7.x, the UTC string is…

Roy Atkins
- 99
- 1
- 2
3
votes
1 answer
Cant' Access API with Powershell but can access using Postman, Python, or cURL
I'm trying to get data back from an API online using Powershell with the command Invoke-WebRequest -UseBasicParsing $request_string -Method Get -Headers $headers) but am getting back Invoke-WebRequest : The remote server returned an error: (403)…

Python Developer
- 551
- 1
- 8
- 18
2
votes
2 answers
Invoke-RestMethod (or Invoke-WebRequest) returning string rather than PS object or JSON
I'm relatively new to using Invoke-RestMethod /Invoke-WebRequest in general- I think that's important context for the below question.
I'm making a call like the below:
$Headers = @{
"Authorization" = "Bearer {0}" -f ($token)
}
$APIUri =…

Johnny Welker
- 104
- 1
- 7
2
votes
1 answer
Translate curl to Powershell Invoke-Restmethod
I'm having issues converting a curl command into Powershell Invoke-RestMethod.
Ihave tried a number of different ways but i get error message: Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
The curl command that i need…

zyntrax
- 88
- 9
2
votes
1 answer
Adding cookies to InvokeRest-Method Powershell
I need to make a POST call to a webserver which is validating usertype from cookies, I couldn't figure out how to add this cookies to my request.
$eth_config = Invoke-RestMethod -Method 'Post' -Uri $network_settings_url -Body $request_body

CleanCoder540
- 57
- 1
- 8
2
votes
3 answers
Invoke-WebRequest -Method 'POST' with -ContentType 'application/json' Fails
When using:
$body = @{
Manager = "spmigrationuser@contoso.com" #$item.PMEmail
Name = "some name"
Number = "Some number"
Practice = "Some Practice"
}
$response =…

Ofer Gal
- 707
- 1
- 10
- 32
2
votes
0 answers
tokenInvoke-WebRequest to site using Microsoft/Google OAuth
I need to access this main site https://www.truecaller.com/search/eg/xxxx via Powershell.
I wrote many PowerShell scripts to Invoke-WebRequest using forms authentication,
but this time the website is using external authentication from Google or…

Powershell Man
- 21
- 2
2
votes
1 answer
Azure Web Job Zip deployment Error due to Size
I am deploying a web job through powershell script and can manage to get the publishing credentials and then add the access token in the authorization header. All is fine until it uploads the zip file when I receive file size error: The remote…

man_luck
- 1,605
- 2
- 20
- 39
2
votes
3 answers
How to convert a response from Invoke-RestMethod to XML?
Referencing the help file for `Invoke-RestMethod:
PS /home/nicholas>
PS /home/nicholas> $response = Invoke-RestMethod -Uri https://blogs.msdn.microsoft.com/powershell/feed/
PS /home/nicholas>
PS /home/nicholas> $json = $response | ConvertTo-Json …

Nicholas Saunders
- 684
- 9
- 28
2
votes
1 answer
How to properly format PSObject to pass to PUT method for InvokeRest Method
Below is the key value pairs I need to pass to the API. Dont know where Im going wrong
$Body = @{
hostName = 'null'
hostOperatingSystem = 0
optionalFilter1 = 'null'
optionalFilter2 = 'null'
description …

Naldo Ash
- 21
- 3
2
votes
0 answers
UseDefaultcredentials is not working for Invoke-RestMethod
Getting unauthorized 401 error when I'm trying to invoke monster API using Invoke-RestMethod with property UseDefaultCredentials.
Invoke-RestMethod -Uri 'https://monster.factset.com/loadbalancerapi/api/Node/viewAll' -Method GET…

Aditya aditi
- 21
- 1
1
vote
2 answers
Python call Powershell Invoke-RestMethod with Json as string into Body
import requests
import subprocess
import base64
credentials = "login:password"
url = f'urlXXXurl'
body = '{"id": 4986986, "key": "2df534ee-270b-4ab4-83fb-1b308febacce", ...}'
headers = '"""@{Authorization = \'Basic %s\'}"""' %…

Takeren
- 45
- 6
1
vote
0 answers
Invoke-RestMethod works on cable but not on Wifi
When connected on Wifi:
PS C:\Users\Julio> Invoke-RestMethod juliobs.com
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive.
At line:1 char:1
+ Invoke-RestMethod juliobs.com
+…

Julio Batista Silva
- 1,861
- 19
- 19