Questions tagged [invoke-restmethod]
129 questions
1
vote
1 answer
Download a file from REST API and upload to Sharepoint without need for intermediate storage
My first post here, as I am newb to scripting/programming.
I have a requirement to download files from an external service via a REST API and then upload those files to SharePoint. I have put together a script that can do this, but it uses…

Micksta
- 23
- 5
1
vote
1 answer
InvalidOperation in PowerShell RestMethod API Call using Bearer sending Body as HASHTABLE
In PowerShell using Invoke-RestMetjhod to call different API´s I am stuck getting an InvalidOperation error when trying to pass both header and body information to the POST call.
My script is:
Set-StrictMode -Version Latest
$ApiToken = Get-Content…

StigK
- 11
- 3
1
vote
1 answer
Powershell Invoke-RestMethod - Formatting response for .csv Export
I'm writing a script to pull order details from an API using Invoke-RestMethod.
I have the response which PS has converted json into a PSCustomObject.
What I'm attempting to do is produce rows in a .csv file where nested array objects are split out…

ColinA
- 99
- 1
- 9
1
vote
0 answers
PowerShell Environment Variable does not equal its string equivalent
Problem
I am unable to use an Environment Variable as a token in an Invoke-RestMethod
I have the following code, that does work:
$props = @{
Uri = $my_url
Method = "POST"
ContentType = "application/json"
Headers = @{ Authorization =…

Tyler
- 85
- 8
1
vote
0 answers
Cannot convert value to powershell
I want to convert cmdlets to windows-1251 encoding so that Russian characters are displayed on the output.
My code:
$result = 'Invoke-RestMethod -Method "Post" -Uri https://ntfy.sh/most -Body "Hello 123 Привет" -UseBasicParsing'
$rus_result = …

kiki
- 11
- 3
1
vote
2 answers
Can't Use Double Quotations to use Variable inside Body for POST Request
$response = Invoke-WebRequest -Uri 'BLAHBLAHBLAH' -Method POST `
-Headers $headers `
-ContentType 'application/json' `
-Body '{"archived":false,"warranty_months":null,
"depreciate":false,
"supplier_id":null,
…

BonesJones
- 11
- 2
1
vote
0 answers
Invoke-RestMethod The underlying connection was closed: An unexpected error occurred on a receive
To Introduce myself : Working as a Power BI Developer with PBI Admin access.
My Powershell script stoped working suddenly and prompting me an error saying the underlying connection was closed. This was all working fine few days…

EricShahi
- 13
- 4
1
vote
1 answer
Extract the last row of list in Powershell
I'm using Powershell to extract data via an API. For some reason, the output is providing multiple rows of data, however I'm only interested in the last row.
As this data is already filtered using
$r = Invoke-WebRequest "HTTP://xyz.xyz"
$lines =…

Taqi Rizvi
- 101
- 9
1
vote
1 answer
Microsoft Graph; Powershell; how to get access token using invoke-restmethod with: TenantID, ClientID and *certificate*
I have researched quite a bit and have not found any information how to get an access token from graph with Powershell via REST by using:
TenantID
Client/AppID
Certificate
with the following conditions:
using invoke-restmethod
What Have I…

John Ranger
- 541
- 5
- 18
1
vote
1 answer
Powershell: Why is $object.AProperty -ne $object['Aproperty']
I am very confused. I'm used to in most programming languages to where referencing a property in the dot notation (e.g. $object.AProperty) is the exact same thing as referencing it in what I'll call the "hashtable" notation (e.g.…

Doug
- 6,446
- 9
- 74
- 107
1
vote
0 answers
Can't pass array value into Invoke-RestMethod URL String
I have the below code snippet that saves a array of ~90 devices to my string $report
$report = Get-ADComputer -Filter * -SearchBase 'OU=Boston, DC=someCompany, DC=com' | Select -ExpandProperty name
Now my issue is when I try to pass this array to…

nick asdf
- 85
- 4
1
vote
1 answer
powershell invoke-webrequest does not work but invoke-restmethod works
I want to get the content of a web page and when I use
$web = Invoke-RestMethod -Uri "https://inkscape.org/"
I will get the content but when I use
$web = Invoke-WebRequest -Uri "https://inkscape.org/"
I won't get anything why it happens?? and what…

atefeh kasiri
- 39
- 5
1
vote
0 answers
Invoke-RestMethod PowerShell problem with Encoding
I am trying to use the Invoke-Restmethod to call a set of API's, but i have a problem with output encoding. What it could be
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
$Header = @{"Authorization" = "Token token_value"}
$uri =…

elpe
- 33
- 2
1
vote
0 answers
403 Forbidden API Gateway on certain workspaces
I've set up an API Gateway using the base example (Pets) in AWS.
On around 5 out of 12 AWS Windows Workspaces that various dev's use, I get a forbidden response.
I've been told by the person who set up the environments around 6 months ago that they…

Richard Whitehouse
- 679
- 3
- 14
- 28
1
vote
1 answer
Invoke-RestMethod Get Request with Query Parameters
I was tasked with spinning up a script for a client which relied on a basic 'GET' request to an API which returned a JSON object which I used info from that to make subsequent calls. This worked great but requirements changed and now I need to send…

LightningBug
- 11
- 3