How to use curl to access the github graphql API

Kasun Siyambalapitiya picture Kasun Siyambalapitiya · Feb 3, 2017 · Viewed 15.3k times · Source

After referring this guide I needed to access the github graphql by using curl for a testing purpose. I tried this simple command

curl -i -H "Authorization: bearer myGithubAccessToken" -X POST -d '{"query": "query {repository(owner: "wso2", name: "product-is") {description}}"}' https://api.github.com/graphql

but it gives me

problems parsing JSON

what I am doing wrong. I spent nearly 2 hours trying to figure it and tried different examples but none of them worked. Can you please be kind enough help me resolve this

Answer

Yuri Schimke picture Yuri Schimke · Feb 3, 2017

You just need to escape the double quotes that are inside the JSON as the query

$ curl -i -H 'Content-Type: application/json' -H "Authorization: bearer myGithubAccessToken" -X POST -d '{"query": "query {repository(owner: \"wso2\", name: \"product-is\") {description}}"}' https://api.github.com/graphql