This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I'm using PowerShell 5, but I'm assuming the same issue applies to older versions.
I'm making a script to pull data from one of our applications (ConnectWise), which has a REST API. For large datasets, the response is paginated. The first x number of records are returned, and the response header includes a "Link" property that links to the next page of information.
This is an example of the response header (pulled from Postman):
Cache-Control →no-cache
Content-Length →105764
Content-Type →application/json; charset=utf-8
Date →Tue, 12 Jul 2016 19:50:38 GMT
Expires →-1
Link →<https://connectwise.contoso.com/v4_6_release/apis/3.0/company/configurations?conditions=name="SaaS/Hosted Information"&pageSize=25&page=2>; rel="next", <https://connectwise.contoso.com/v4_6_release/apis/3.0/company/configurations?conditions=name="SaaS/Hosted Information"&pageSize=25&page=8>; rel="last"
Pragma →no-cache
Server →Microsoft-IIS/8.5
X-AspNet-Version →4.0.30319
X-Powered-By →ASP.NET
x-server-name →CONNECTWISE
I can't figure out how to get the response header information from Invoke-RestMethod. I've tried:
- Setting a session variable, and looking to see if it contains the response headers (no luck)
- Setting an error variable, and looking to see if it contains response headers (no luck)
- Looked at all the variables defined in all scopes to see if there is a $response variable or something that holds the response headers (no luck)
- Looking at the payload returned from Invoke-RestMethod to see if it embeds it in the response somewhere (no luck).
Am I missing something, or does Invoke-RestMethod just discard the response headers entirely? Any ideas on how to get the response headers without writing my own function?\
EDIT: Looks like Invoke-RestMethod just throws away the response headers unless there is an error. Using Invoke-WebRequest is the workaround. Thanks for the help everyone!
Subreddit
Post Details
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PowerShell/...