Skip to content

Invoke-RestMethod doesn't return useful info when no data is returned. #5320

@thezim

Description

@thezim

Steps to reproduce

You will need to generate an API token and grant the notifications privilege.

PS /Users/greg> $apitoken = "yourapitoken"
PS /Users/greg> $headers = @{ Authorization = "token $apitoken" }
PS /Users/greg> $resp = Invoke-RestMethod -Uri https://api.github.com/notifications -Headers $headers
PS /Users/greg> $resp -eq $null                                                                                                     
PS /Users/greg>

What is returned is an Object.

PS /Users/greg> $resp -is [System.Object]                                                                                           
True
PS /Users/greg> 

Should be no different than this.

PS /Users/greg> $obj = New-Object System.Object                                                                                     
PS /Users/greg> $obj -eq $null                                                                                                      
False
PS /Users/greg> 

Expected behavior

PS /Users/greg> $resp -eq $null
True
PS /Users/greg>

Actual behavior

PS /Users/greg> $resp -eq $null
PS /Users/greg>

Environment data

Name                           Value                                                                                               
----                           -----                                                                                               
PSVersion                      6.0.0-beta.9                                                                                        
PSEdition                      Core                                                                                                
GitCommitId                    v6.0.0-beta.9                                                                                       
OS                             Darwin 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/R...
Platform                       Unix                                                                                                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                             
PSRemotingProtocolVersion      2.3                                                                                                 
SerializationVersion           1.1.0.1                                                                                             
WSManStackVersion              3.0

This occurs for Windows PowerShell versions too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-Changebreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions