Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot upload github release asset through API

Tags:

github-api

I have a github release with no assets yet:

$ curl https://api.github.com/repos/cljsinfo/api-docs/releases/1260660/assets
[

]

But I cannot upload an asset to this release:

$ curl -X POST --header "Content-Type:application/edn" --data-binary @cljsdocs-full.edn "https://api.github.com/repos/cljsinfo/api-docs/releases/1260660/assets?name=full.edn&access_token=$(cat my-token)"
{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

my api access token has public_repo access. Thanks for any helping on uploading this asset.

like image 675
Shaun Lebron Avatar asked May 06 '15 02:05

Shaun Lebron


2 Answers

You're making the POST request to https://api.github.com/repos/cljsinfo/api-docs/releases/1260660/assets which is not the upload URL for the release. It should be https://uploads.github.com/repos/cljsinfo/api-docs/releases/1260660/assets.

See the docs for more info:

https://developer.github.com/v3/repos/releases/#upload-a-release-asset

like image 81
Ivan Zuzak Avatar answered Jan 02 '23 02:01

Ivan Zuzak


The asset upload URL is of the form https://<upload_url>/repos/:owner/:repo/releases/:id/assets?name=foo.zip. There are several possible reasons you might get the very unhelpful "Not Found" error:

  1. Wrong release id. The :id field in the URL above is NOT the name you gave the release, but a numeric id generated by GitHub (probably a database ID). To get the release ID, you have to call the releases API and search through the JSON response for a release where the tag_name is equal to the name you used. For example, if you named your release v0.0.3, search in the JSON for a release with "tag_name": "v0.0.3" and use that release's id field.
  2. Wrong upload URL. The URL you use to upload assets is not the same one ou use for all other API calls. To get the right upload URL, you use the same releases API, find your release using tag_name a described above, and extract the upload_url field from the JSON response. This is Ivan's (accepted) answer.
  3. Missing GitHub access token permissions. This is the one that tripped me up the worst, as the token I was using was able to make API calls to the releases API and get info about my repo, but NOT upload assets to that same repo. The "Not Found" error response doesn't hint at this at all. Check the permissions for your token in your personal access tokens page and make sure repo and/or public_repo are checked, as appropriate.
like image 37
Yevgeniy Brikman Avatar answered Jan 02 '23 04:01

Yevgeniy Brikman