12

I am trying to download the logs of a particular workflow in github. I have referenced the following link for the same. However I am getting 302 as response code. Not sure what the issue here is. Its not downloading logs as expected

 curl -v -u username:$token -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/ORGANIZATION/REPOSITORY/actions/runs/319282523477/logs
.
.
< HTTP/1.1 302 Found
< Date: Wed, 21 Oct 2020 07:47:13 GMT
< Content-Type: text/html;charset=utf-8
.
codeaprendiz
  • 2,703
  • 1
  • 25
  • 49

2 Answers2

4

As per the same documentation that you mentioned:

Gets a redirect URL to download a plain text file of logs for a workflow job. This link expires after 1 minute. Look for Location: in the response header to find the URL for the download

Response Status: 302 Found

So you might have already got the url to download the logs as the response has a 302 http status. Please check for the Location: response header, which should give you the url that you need to download the logs.

Madhu Bhat
  • 13,559
  • 2
  • 38
  • 54
  • Thanks a lot @Madhu, as you said there is one `Location:` header containing the url to download the logs. This URL works fine on chrome but is not working with agents like curl or wget. Any reason why ? – codeaprendiz Oct 21 '20 at 08:25
  • @codeaprendiz Should ideally work on any http client. The link expires in a min as specified in the doc, did you try it with curl immediately after generating the link? What response did you get when you tried with curl? – Madhu Bhat Oct 21 '20 at 08:29
  • yes I tried with curl actually. Its giving `< HTTP/2 404` response. The same link is working with chrome. – codeaprendiz Oct 21 '20 at 08:33
  • @codeaprendiz Might possibly be some difference with the way you are making the curl request. Can you share the url and how you're trying with curl? – Madhu Bhat Oct 21 '20 at 08:39
  • was trying with this simple command `curl -v $URL` and also tried with `wget $URL`. $URL is working on chrome and downloads the file. – codeaprendiz Oct 21 '20 at 09:53
  • 1
    I won't be able to check unless you share the url. Or else you can check the network tab on developer tools of chrome while you open the url in chrome and check the request being made. – Madhu Bhat Oct 21 '20 at 09:59
  • 1
    @codeaprendiz you need to authenticate to download the log iirc – riQQ Oct 22 '20 at 16:38
  • ah okay @riQQ, yeah this makes sense. `curl -u username:password` $URL should do the trick. In chrome might have worked as i was already logged in i guess. Thanks a lot @riQQ. – codeaprendiz Oct 23 '20 at 08:29
2

As a side note to Madhu Bhat's answer, you can simply add -L to your curl command to make it follow redirects.

(from curl --help)

 -L, --location      Follow redirects
  • 1
    That would be "curl -L -H "Authorization: ..."" --output .zip" (ignoring that the internal quotes are wrong) with auth and entire url filled in. This will follow redirection to download the file. Standard unzipping will work on it. – Lee Meador Feb 13 '23 at 22:22