REST API v3: Not able to create repo using the code given in the guide

I used the code given here - https://developer.github.com/v3/guides/getting-started/#create-a-repository - to create a repo using REST API v3. But it errors out with a message Problems parsing JSON. I have even replaced the OAuth token with my own. Can someone help me out?

Can you post your exact code or curl example (with OAuth tokens redacted) so we can see what you’re doing? Difficult to provide feedback without that.

3 Likes

@abinoda Heres the code -

curl -i -H "Authorization: token \<OAuth token\>" \ -d '{ \
        "name": "blog", \
        "auto_init": true, \
        "private": true, \
        "gitignore_template": "nanoc" \
      }' \
    https://api.github.com/user/repos

The above code gets the parsing JSON error.

But if I put everything in one line then the request works

The one line code - 

curl -i -H "Authorization: token <OAuth token>" -d '{"name": "blog", "auto_init": true, "private": true, "gitignore_template": "nanoc"}' https://api.github.com/user/repos`

Try this, I think it’s cleaner:

curl -i -X POST https://api.github.com/user/repos \
-H "Authorization: token <OAuth token>" \
-d @- << EOF
{
  "name": "blog",
  "auto_init": true,
  "private": true,
  "gitignore_template": "nanoc"
}
EOF
2 Likes

 @abinoda That worked, thx for the help.

I think that the guide should be updated as this was not the only code that had the same error.

Can i pass parameters like “created_at” “updated_at” “pushed_at” ? It says problems parsing json,