
Fix needed for PHP POST Curl to GraphQL ShopifyAPI
- or -
Post a project like this1730
£25(approx. $34)
- Posted:
- Proposals: 1
- Remote
- #2975062
- PRE-FUNDED
- Awarded
Description
Experience Level: Entry
Estimated project duration: 1 day or less
I am using PHP to communicate with the Shopify GraphQL API. Credentials are verified, test "read" calls work fine. Why is this code not working? I cannot for the life of me figure it out.
$url = 'https://'. $STORE_URL . '/admin/api/2020-07/graphql.json';
$curl = curl_init();
$queryData = array();
$data = array();
$queryData = 'mutation orderEditSetQuantity('.$OrderID.': ID!, '.$OrderLineItemID.': ID!, '.$newQuantity.': Int!) {
orderEditSetQuantity(id: '.$OrderID.', lineItemId: '.$OrderLineItemID.', quantity: '.$newQuantity.') {
calculatedLineItem {
id
}
calculatedOrder {
id
}
userErrors {
field
message
}
}
}';
$data["query"] = $queryData;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Shopify-Access-Token: ' .$SECRET
));
return curl_exec($curl);
I have tried everything, every combination of encoding/decoding, option toggles, even clunky manual string replaces, but CONSTANTLY I get this error returned:
{"errors":[{"message":"Parse error on \"26565467347\" (INT) at [1, 31]","locations":[{"line":1,"column":31}]}]}
What is going on?
$OrderID is an integer. There is no reason for it to even have double quotes around it. I figure this must be something to do with how the data is transmitted via POST so it is somehow decoded incorrectly on the other side.
If you have experience working with GraphQL, it is obviously preferred. Shopify API is maybe a bonus, but I THINK probably not required.
I think this is surely a very basic project, probably just a few lines of code will fix the issue, and my pricing will reflect that, I hope you consider that reasonable, I'll be watching this page like a hawk today because I really want to get moving on this thing so if anyone wants a quick, simple project for a modest payout - and you can genuinely help! Please do apply.
$url = 'https://'. $STORE_URL . '/admin/api/2020-07/graphql.json';
$curl = curl_init();
$queryData = array();
$data = array();
$queryData = 'mutation orderEditSetQuantity('.$OrderID.': ID!, '.$OrderLineItemID.': ID!, '.$newQuantity.': Int!) {
orderEditSetQuantity(id: '.$OrderID.', lineItemId: '.$OrderLineItemID.', quantity: '.$newQuantity.') {
calculatedLineItem {
id
}
calculatedOrder {
id
}
userErrors {
field
message
}
}
}';
$data["query"] = $queryData;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-Shopify-Access-Token: ' .$SECRET
));
return curl_exec($curl);
I have tried everything, every combination of encoding/decoding, option toggles, even clunky manual string replaces, but CONSTANTLY I get this error returned:
{"errors":[{"message":"Parse error on \"26565467347\" (INT) at [1, 31]","locations":[{"line":1,"column":31}]}]}
What is going on?
$OrderID is an integer. There is no reason for it to even have double quotes around it. I figure this must be something to do with how the data is transmitted via POST so it is somehow decoded incorrectly on the other side.
If you have experience working with GraphQL, it is obviously preferred. Shopify API is maybe a bonus, but I THINK probably not required.
I think this is surely a very basic project, probably just a few lines of code will fix the issue, and my pricing will reflect that, I hope you consider that reasonable, I'll be watching this page like a hawk today because I really want to get moving on this thing so if anyone wants a quick, simple project for a modest payout - and you can genuinely help! Please do apply.

Company Ltd
100% (25)Projects Completed
19
Freelancers worked with
19
Projects awarded
68%
Last project
20 Dec 2023
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies