Question

I am attempting to update a file in one of my repos via the API.

Here is my get of that file (works nicely):

curl -XGET 'https://git.fake.local/api/v3/repos/jsmith/repo_version/contents/version.html?ref=gh-pages'
{
  "name": "version.html",
  "path": "version.html",
  "sha": "b1b716105590454bfc4c0247f193a04088f39c7f",
  "size": 5,
  "url": "https://git.fake.local/api/v3/repos/jsmith/post_version/contents/version.html?ref=gh-pages",
  "html_url": "https://git.fake.local/jsmith/post_version/blob/gh-pages/version.html",
  "git_url": "https://git.fake.local/api/v3/repos/jsmith/post_version/git/blobs/b1b716105590454bfc4c0247f193a04088f39c7f",
  "type": "file",
  "content": "aW5pdAo=\n",
  "encoding": "base64",
  "_links": {
    ...
  }
}

Here is my attempt to update that file via PUT:

curl -XPUT 'https://git.fake.local/api/v3/repos/jsmith/repo_version/contents/version.html?ref=gh-pages' -d '{
   "message": "update from api",
   "committer": {
     "name": "Joe Smith",
     "email": "jsmith@fake.com"
   },
   "content": "bXkgdXBkYXRlZCBmaWxlIGNvbnRlbnRz",
   "sha": "b1b716105590454bfc4c0247f193a04088f39c7f"
 }'

RESULT:

{
  "message": "Not Found"
}
Was it helpful?

Solution

Okay... I think I got it.

From the github doco:

Authentication

There are three ways to authenticate through GitHub API v3. Requests that require authentication will return 404 Not Found, instead of 403 Forbidden, in some places. This is to prevent the accidental leakage of private repositories to unauthorized users.

I was expecting a 403 if Auth was a problem but they are throwing a 404, so basically I probably need to make sure I am auth'd correctly and all will be well.

SOLVED: I created a personal oauth token (under settings/applications) and add to curl request in header and it all works great.

curl -XPUT -H "Authorization: token MYSECRETTOKEN"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top