Reputation: 129
I am trying to create a release using Github's API.
My request works fine in Postman but no matter what I've tried it always fails with curl, including if I just translate my Postman request into curl using Postman.
This is the body of my Postman POST request:
{
"tag_name": "4.2.0",
"target_commitish": "master",
"name": "4.2.0",
"body": "test"
}
I've included an authorization header of type "Basic", where I input my username and a token I have created for this purpose.
I am executing the request against https://api.github.com/repos/<myUsername>/<myRepo>/releases
.
As I said - it works fine, but when I translate it into curl I get the error "Problems parsing JSON".
The translated curl command is:
curl --location --request POST 'https://api.github.com/repos/<myUsername>/<myRepo>/releases' \
--header 'Authorization: Basic <someHashOrSomething>' \
--header 'Content-Type: application/json' \
--data-raw '{
"tag_name": "4.2.0",
"target_commitish": "master",
"name": "4.2.0",
"body": "test"
}'
which I reformat into curl --location --request POST 'https://api.github.com/repos/<myUsername>/<myRepo>/releases' --header 'Authorization: Basic <someHashOrSomething>' --header 'Content-Type: application/json' --data-raw '{ "tag_name": "4.2.0", "target_commitish": "master", "name": "4.2.0", "body": "test"}'
to be on one line.
I also tried (since only the "tag_name" parameter is required):
curl -i -H 'Authorization: token <myToken>' -d '{"tag_name":"4.2.0"}' https://api.github.com/repos/<myUsername>/<myRepo>/releases
curl -i -H 'Authorization: token <myToken>' -d '{"tag_name":"4.2.0"}' https://api.github.com/repos/<myUsername>/<myRepo>/releases --header Content-Type:application/json
curl -d '{"tag_name":"4.2.0"}' -u <myUsername>:<myToken> https://api.github.com/repos/<myUsername>/<myRepo>/releases --header "Content-Type:application/json"
curl -d "tag_name=4.2.0" -u <myUsername>:<myToken> https://api.github.com/repos/<myUsername>/<myRepo>/releases --header "Content-Type:application/json"
Every curl request fails with the "Problems parsing JSON" error.
Upvotes: 2
Views: 7425
Reputation: 1681
How to debug:
Remember that It is so important to make sure that curl receives valid JSON data.
See an example of Powershell here:
Upvotes: 1
Reputation: 61
If you are doing this from the windows cmd prompt, you need to change
--data-raw '{ "tag_name": "4.2.0", "target_commitish": "master", "name": "4.2.0", "body": "test"}'
to
--data-raw "{ \"tag_name\": \"4.2.0\", \"target_commitish\": \"master\", \"name\": \"4.2.0\", \"body\": \"test\"}"
cmd prompt appears to not like single quotes for the data.
Upvotes: 6
Reputation: 669
The problem could be your API key.
Check if it has the sufficient permissions or try and create a new one.
Upvotes: -5