I am querying Github API for some internal monitoring interface. I came across the new GraphQL implementation in the documentation and decided to use it for my interface.
Accordingly, I prepared this small PHP script to test the Github GraphQL API which I have pasted below. I always get ‘Problems parsing JSON’ error whenever I run the script. Am I doing something wrong here? Can somebody help me highlight any mistake I am doing?
<?php
//GRAPHQL request
$postData =<<<‘JSON’
{
“query”: query{
user(login:“tojochacko”) {
name
}
}
}
JSON;
$json = json_encode($postData);
$chObj = curl_init();
curl_setopt($chObj, CURLOPT_URL, ‘https://api.github.com/graphql’);
curl_setopt($chObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chObj, CURLOPT_CUSTOMREQUEST, ‘POST’);
curl_setopt($chObj, CURLOPT_POSTFIELDS, $json);
curl_setopt($chObj, CURLOPT_HEADER, true);
curl_setopt($chObj, CURLOPT_VERBOSE, true);
curl_setopt($chObj, CURLOPT_HTTPHEADER,
array(
‘User-Agent: PHP Script’,
‘Content-Type: application/json’,
'Authorization: bearer '.GITHUB_TOKEN
)
);
$response = curl_exec($chObj);
echo $response;
?>