1

I am trying to construct a curl request that will allow me to automate the task of attaching a binary to a release in GitHub (so dragging a file into the box).

From the API docs I can see that we need to obtain the id of the release (which I have already obtained from a prior call):

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

At the moment I get

curl --header {"Content-Type": "application/zip"} --data \'{"name": "path_to_zip_file"} "https://api.github.com/repos/owner/my_repo/releases/:id/assets?access_token=acces_token"

I get a response like with a lot of other

Hello future GitHubber! I bet you're here to remove those nasty inline styles, DRY up these templates and make 'em nice and re-usable, right?`

 <p><strong>We didn't receive a proper request from your browser.</strong></p>
halfer
  • 19,824
  • 17
  • 99
  • 186
Richlewis
  • 15,070
  • 37
  • 122
  • 283
  • Here's a full working Python example: https://stackoverflow.com/questions/5207269/how-to-release-a-build-artifact-asset-on-github-with-a-script/52354732#52354732 This task is likely a bit too insane for `curl`, specially since you must fetch the ID first. – Ciro Santilli OurBigBook.com Sep 17 '18 at 07:09

1 Answers1

2

You send JSON payload in your request, but the docs you linked say you need to make a POST request with the raw binary file contents as payload.
Also you miss to set the Content-Type header correctly.
Change your curl call to supply the file as payload, add the filename as parameter to the URL and set the header like described in the docs and it should work fine.

The resulting command should be something like: curl 'https://api.github.com/repos/owner/my_repo/releases/:id/assets?access_token=acces_token&name=foo.zip' --header 'Content-Type: application/zip' --upload-file test.zip -X POST

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • I'd just like to add a comment for those who are using this answer. Keep in mind it's access_token and not acces_token, and the upload url may be different for your repo. I believe most of them are upload.github.com, not api.github.com. Get the release to find the as specified in the [documentation](https://developer.github.com/v3/repos/releases/#get-a-single-release) – Allan W Mar 21 '17 at 22:25
  • 1
    my mistake, I was looking at `access_token=**acces_token**` but that didn't make a difference. As for the upload url, as per the documentation (which is also linked in the original question), the url may be `uploads.github.com`, which still uses the api. Posting to `api.github.com` won't work. – Allan W Mar 22 '17 at 21:27