Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 5

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

Solved! Go to Solution.

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?

4 Replies
Pilot Lvl 1
Message 2 of 5

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

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.

Highlighted
Copilot Lvl 3
Message 3 of 5

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

@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`

 

Solution
Pilot Lvl 1
Message 4 of 5

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

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
Copilot Lvl 3
Message 5 of 5

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

 @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.