git - GitHub API to Create a File -
so i'm trying familiarize myself github api. i'm using curl commands implement of basic functionality. can basic authorization & repository creation correctly. currently, i'm trying create file in repository using api & facing "message":"not found" error response.
their documentation suggests this:
put /repos/:owner/:repo/contents/:path i came curl equivalent:
curl -h 'authorization: <token>' -d '{"path": "test.txt", "message": "initial commit", "committer": {"name": "<name>", "email": "<email>"}, "content": "bxkgbmv3igzpbgugy29udgvudhm=", "note":"test commit"}' https://api.github.com/repos/invin-test/test_repo1/contents/test.txt i think problem api url i'm using @ end, can't seem figure out url should like.
this used create repository:
curl -i -h 'authorization: <token>' -d '{"name": "test_repo1", "message": "initial commit", "committer": {"name": "<name>", "email": "<email>"}, "content": "bxkgbmv3igzpbgugy29udgvudhm=", "note":"test commit"}' https://api.github.com/user/repos the repository creation url used follows: user/repos syntax. similarly, i've tried using user/repos/repo, didn't work.
can shed light on this?
i've gone through various stackoverflow questions & many seem similar none offer example can figure out mistake lies.
edit: timwolla answer.
syntax of working command create file in repository using github api:
curl -i -x put -h 'authorization: token <token_string>' -d '{"path": "<filename.extension>", "message": "<commit message>", "committer": {"name": "<name>", "email": "<e-mail>"}, "content": "<base64 encoded>", "branch": "master"}' https://api.github.com/repos/<owner>/<repository>/contents/<filename.extension>
my example:
curl -i -x put -h 'authorization: token f94ce61613d5613a23770b324521b63d202d5645' -d '{"path": "test4.txt", "message": "initial commit", "committer": {"name": "neil", "email": "neil@abc.com"}, "content": "bxkgbmv3igzpbgugy29udgvudhm=", "branch": "master"}' https://api.github.com/repos/invin-test/test_repo1/contents/test4.txt
when using curl need specify correct http verb (put in case) using -x option:
curl -x put -h 'authorization: …' yadayada also using example payload error 500 showed up, shortened payload worked fine:
{"message": "initial commit","content": "bxkgbmv3igzpbgugy29udgvudhm="} i don't know actual reason server error, though.
Comments
Post a Comment