GitHub API to Create a File

So I'm trying to familiarize myself with the GitHub API. I'm using cURL commands to implement some of their basic functionality. I can get the basic authorization & repository creation correctly. Currently, I'm trying to create a file in a repository using their API & am facing the "message":"Not Found" error as the response.

Their documentation suggests this:

PUT /repos/:owner/:repo/contents/:path

I came up with this as the cURL equivalent:

curl -H 'Authorization: <token>' -d '{"path": "test.txt", "message": "Initial Commit", "committer": {"name": "<name>", "email": "<email>"}, "content": "bXkgbmV3IGZpbGUgY29udGVudHM=", "note":"Test Commit"}'

I think the problem is with the API URL I'm using at the end, but I can't seem to figure out what the URL should look like.

This is what I used to create a repository:

curl -i -H 'Authorization: <token>' -d '{"name": "test_repo1", "message": "Initial Commit", "committer": {"name": "<name>", "email": "<email>"}, "content": "bXkgbmV3IGZpbGUgY29udGVudHM=", "note":"Test Commit"}'

The repository creation URL I used follows: user/repos as the syntax. Similarly, I've tried using user/repos/repo, but it didn't work.

Can anyone shed any light on this?

I've gone through various StackOverflow questions & many seem similar but none really offer an example so I can figure out where the mistake lies.

EDIT: Thanks to TimWolla for the answer.

Syntax of a working command to create a file in a repository using the 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"}'<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": ""}, "content": "bXkgbmV3IGZpbGUgY29udGVudHM=", "branch": "master"}'


When using curl you need to specify the correct HTTP Verb (PUT in this case) using the -X option:

curl -X PUT -H 'Authorization: …' yadayada

Also using your example payload an error 500 showed up, this shortened payload worked fine:

{"message": "Initial Commit","content": "bXkgbmV3IGZpbGUgY29udGVudHM="}

I don't know the actual reason for the Server error, though.

Need Your Help

Floor in Haskell and Ints

haskell int floor

When I use floor in Haskell i.e. floor 1.7 I assumed it would give me 1 and it's type would be an Int but I keep getting an error message as if this is not the case?

Exclude files or certain type when writing to Amazon AWS S3

powershell amazon-web-services svg amazon-s3 aws-powershell

I am trying to upload folders to S3 to serve as static website. The problem I have is that within the folders, there are files of certain extensions such as .css, .png, .svg, etc. I am using AWS