Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 9

Programatically download private repository using Curl

Hi, 

 

I am going nuts figuring this out , going through tons of google/stackflow/blogs pages but have not found clear answer.

I would like to programatically download repository in ZIP format using Curl and my personal github token.

Assume:

$token -> my personal token

$org -> my organization as a owner of repositories

$repo -> private repository I would like to download

 

I am trying to use something like this:

curl -H "Authorization: $token" -L https://api.github.com/repos/$org/$repo/zipball > repo.zip

 

but it produces following json:

{

  "message": "Not Found",

  "documentation_url": "https://developer.github.com/v3/repos/contents/#get-archive-link"

}

 

Please help !!

 

8 Replies
Highlighted
Community Manager
Message 2 of 9

Re: Programatically download private repository using Curl

Hey @dq-shripad,

 

Thanks for being here! AFAIK the supported and reliable way of downloading an archive file of repository contents programmatically is to correctly authenticate with the API and use the Get archive link API endpoint.

 

I hope this helps!


I hope this helps,
Andrea

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Highlighted
Copilot Lvl 3
Message 3 of 9

Re: Programatically download private repository using Curl

Thanks AndreaGriffiths11.

 

I think the issue was not with authentication but authorization. I have shared my findings.

Highlighted
Ground Controller Lvl 1
Message 4 of 9

Re: Programatically download private repository using Curl

This helped me. Thanks!

 

download_release() {
    TOKEN="xxxxxxxxx"
    REPO=":owner/:repo"
    curl -vLJO https://$TOKEN:@api.github.com/repos/$REPO/zipball/master
}
Highlighted
Ground Controller Lvl 1
Message 5 of 9

Re: Programatically download private repository using Curl

...and for those like me who got here looking for a one-liner command line to clone private repos on other servers, the command is simply:

git clone https://**yourtoken**@github.com/*user*/*repo*.git 

 

A token can be generated here: https://github.com/settings/tokens

Copilot Lvl 3
Message 6 of 9

Re: Programatically download private repository using Curl

 

finally figured out the issue.

 

The problem was not in curl option/syntax used on command-line.

 

The problem was in personal access token I had created. I was using an access token created with basic and repo permissions. Aparently, this was not enough.

I then created another access token will full permissions (every permission setting offered ) and with this token I was able to extract repo zip file. 

 

two things I would like to point out :

1) The first token created should have worked....not sure why it didn't. I should not have to create a token will all permissions.

2) When I used first token, Github API reported that "repositary not fund" even though it existed.!  The message should have been "access token does not have required permissions " or simply "bad credentials ".

Hope Github API team can review this and make changes to their messaging.

 

 

 

 

 

Highlighted
Ground Controller Lvl 1
Message 7 of 9

Re: Programatically download private repository using Curl

Hi 

I am also facing a similar kind of issue.

Can you please send me the exact query that you were using.

In my case i need to access the latest release tag name 

and download the zip file.

curl -H "Authorization: token tokenid" https://github.URL.com/orgname/reponame/releases/latest

curl -u username:token https://github.url.com/orgname/reponame/releases/latest

the above two did not work.

 

 

Highlighted
Copilot Lvl 2
Message 8 of 9

Re: Programatically download private repository using Curl

You're missing a "-L " prior to the repo, for instance
Also I don't know if "releases/latest" work
For me I did "/me/repo/tar.gz/master"

e.g.
curl -H "Authorization: token $GITHUB_MASTER" -L https://codeload.github.com/me/repo/tar.gz/master > repo.tar.gz

Highlighted
Commander Lvl 1
Message 9 of 9

Re: Programatically download private repository using Curl

Hey! It seems you can only download a release and it's subsequent zip file, but this part of the API will allow you to do this: https://developer.github.com/v3/repos/releases/#get-a-single-release-asset



*Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!*