0

I have searched extensively for a solution but have yet to find success. I just want to be able to download files from my private GitHub repo using PowerShell. I want to use OAuth, not basic auth, so I have generated a token. But from here, none of the examples I've referenced worked for me. Best I could do was get a "Not Found" response.

An example of code I've tried is:

Invoke-WebRequest https://api.github.com/repos/MyAccount/MyRepo/contents/MyFile.txt -Headers @{"Authorization"="token 123456789012345678901234567890"} -OutFile C:\Temp\MyFile.txt

Result:

Invoke-WebRequest : {"message":"Not Found","documentation_url":"https://docs.github.com/rest/reference/repos#get-repository-content"}

I'm fairly confident that I have the authentication right. I believe I just have the path wrong path to my file. Any help would be greatly appreciated.

RaymonS
  • 3
  • 5

1 Answers1

0

Potential Duplicate use case relative to this SO discussion ...

PowerShell: retrieve file from GitHub

$url = 'https://github.com/mycompany/myrepo/blob/master/myscript.ps1'
$wc  = New-Object -TypeName System.Net.WebClient
$wc.Headers.Add('Authorization','token your_token')
iex ($wc.DownloadString($url))

.. without Invoke-WebRequest of course.

See also:

Using PowerShell and oAuth

# Modified article code
Invoke-RestMethod https://api.github.com/repos/MyAccount/MyRepo/contents/MyFile.txt -Method Get -Headers @{"Authorization" = "Bearer $accessToken"} 
postanote
  • 12,933
  • 2
  • 10
  • 19
  • I did find and try to use that post already. I get the same "Not Found" response with Invoke-RestMethod and WebClient. Changing up my token at all gives a "Bad Credentials" response, so I know I have the auth part right. I just need to figure out the correct path to my files. – RaymonS Aug 20 '20 at 20:25