Uploading new File

I must be missing something very simple here…

based on this:

I would expect uploading a new file would be fairly trivial, but I keep getting an error.

{"message":"Problems parsing JSON","documentation_url":"https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}

I am doing the PUT via C# and a HttpWebRequest.

What is being sent to the server is this (Token Redacted):

PUT https://api.github.com/repos/BrienKing/FPGA-Cat-Box-Signature-Files/contents/Atari/Centipede/Centipede%20Address%20Lines%20Part%202.txt HTTP/1.1
Content-Type: application/json
User-Agent: fpga-cat-box-signature-analysis
Accept: application/vnd.github.v3+json
Authorization: token <token>
Host: api.github.com
Content-Length: 597
Expect: 100-continue

{message: "Test Commit", committer:{ name: "Brien King", email:"spammehere@arcaderestoration.com"}, content: "R2FtZQlDZW50aXBlZGUNDQ0NDQpEZXNjcmlwdGlvbglBZGRyZXNzIExpbmVzDQ0NDSBQYXJ0IDINCk5vdGVzCQ1Gb3IgdGhlIGZvbGxvd2luZyB0ZXN0cywgZ3JvdW5kIEoyIFBpbiAxDQpOb3RlcwkNClN0YXJ0CU5FRw0KU3RvcAlORUcNCkNsb2NrCVBoYXNlMglORUcNClN0b3AgdG8gc3RhcnQJDQpDbG9jayB0byBQaGFzZTIJDQpFbmFibGUgYWRkciBjb3VudGVyCQ0KU3RhcnQgdG8gQTE1CQ0KRm9yY2UgV3JpdGUJRkFMU0UNCk5PUCBNb2RlCUZBTFNFClNpZ25hbAlMb2NhdGlvbglQaW4JU2lnbmF0dXJlDQoJCTAJDQpQRldSMwlKMgk3CTExVTYNClBGV1IyCUoyCTYJMUMzRg0KUEZXUjEJSjIJNQk0Rkg3DQpQRldSMAlKMgk0CTQ2MUY=" }

The response I get back is this:

HTTP/1.1 400 Bad Request
Server: GitHub.com
Date: Sun, 11 Oct 2020 03:04:17 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 133
Status: 400 Bad Request
X-OAuth-Scopes: public_repo, repo:status
X-Accepted-OAuth-Scopes: 
X-GitHub-Media-Type: github.v3; format=json
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4997
X-RateLimit-Reset: 1602388326
X-RateLimit-Used: 3
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Frame-Options: deny
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
Content-Security-Policy: default-src 'none'
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: EABD:5298:87317E:127C39E:5F82762B

{"message":"Problems parsing JSON","documentation_url":"https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}

Any idea what I might be doing wrong?

Thank you!

If this is actually the payload:

… then it’s indeed invalid JSON. The attribute keys aren’t wrapped in double quotes. It should be:

{"message": "Test Commit", "committer":{ "name": "Brien King", "email":"spammehere@arcaderestoration.com"}, "content": "R2FtZQ..." }
1 Like

Yes, that was it. I knew I was missing something very simple. Couldn’t see the forest because of all the trees :slight_smile:

1 Like