Hi,
I am starting to migrate my Shoppify app from REST to graphgl.
I have followed the documentation and tried many variations on this code, but I always get back ‘1’
I am using php code with a raw CURL call.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $baseUrl,
CURLOPT_POSTFIELDS => $postFields,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => TRUE,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’,
‘X-Shopify-Access-Token:’ . $apiKey,
),
));
$response = curl_exec($curl);
where the base url is
https://my-store.myshopify.com/admin/api/2025-01/graphgl.json
$postfields is;
$query = <<<QUERY
query GetProducts {products(first: 10) {nodes{id title}}}
QUERY;
then;
$postFields = array(
‘query’ => $query
);
I have tried this as string, with new lines, json encoded, not encoded etc etc.
Has anyone any Idea whats going on here?
If I use a made up url, I get not found error. So it is connecting.
The $apiKey (The token) appears to be valid as again if I put random data in it errors.
I am using POST as that is what the documentation says to use, even though this is only a GET.
I have been reading other posts, no one is getting this issue but I am thinking is my query wrong ?
So I have tried this one from another post;
$query = <<<QUERY
query { customers(first:1, query: “country:canada”) { edges { node { id displayName firstName lastName } } }}
QUERY;
still get a 1 as the response.
I have found another example of getting the first teo products, slightly different query;
$query = <<<QUERY
query {products(first:10) {edges {nodes {id title}}}}
QUERY;
But again, returns a 1