From 736ed99d4d6db1a396ca264903b2f010ad11f99e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Tue, 10 Dec 2024 00:15:30 +0100 Subject: [PATCH] API fix --- examples/CallingAPIs.ps1 | 1 + src/functions/public/API/Invoke-GitHubAPI.ps1 | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/CallingAPIs.ps1 b/examples/CallingAPIs.ps1 index b1488e439..c38d29dce 100644 --- a/examples/CallingAPIs.ps1 +++ b/examples/CallingAPIs.ps1 @@ -43,4 +43,5 @@ Invoke-GitHubAPI -ApiEndpoint /zen # Most complex example - output is the entire web response $context = Get-GitHubContext Invoke-WebRequest -Uri "https://api.$($context.HostName)/zen" -Token ($context.Token) -Authentication Bearer +Invoke-RestMethod -Uri "https://api.$($context.HostName)/octocat" -Token ($context.Token) -Authentication Bearer #endregion diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index eb78c7265..c8733ad93 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -193,10 +193,15 @@ 'text/plain' { $results = $response.Content } + 'application/octocat-stream' { + [byte[]]$byteArray = $response.Content + $results = [System.Text.Encoding]::UTF8.GetString($byteArray) + } default { Write-Warning "Unknown content type: $($headers.'Content-Type')" Write-Warning 'Please report this issue!' - $results = $response.Content + [byte[]]$byteArray = $response.Content + $results = [System.Text.Encoding]::UTF8.GetString($byteArray) } } [pscustomobject]@{