Questions and discussions about using the Shopify CLI and Shopify-built libraries.
Hi
I'm using PHPShopify to send GraphQL queries and mutations to my dev shop.
The following code is to deactivate a discount code, using GraphQL and the PHPShopify library
$graphQL = <<<Query mutation discountCodeDeactivate($id: ID!) { discountCodeDeactivate(id: $id) { userErrors { field message } } } Query; $variables = [ "input" => [ "id" => '12345' ] ];
I keep getting the following error
Uncaught PHPShopify\Exception\ApiException: message - Parse error on ":" (COLON) at [1, 33],
I know it's because of the variable, but can't figure out why. I've tried swapping $id to $input but it's the same error.
Any ideas why?
Solved! Go to the solution
This is an accepted solution.
You need to escape the $id with a "/".
$graphQL = <<<Query mutation discountCodeDeactivate(/$id: ID!) { discountCodeDeactivate(id: /$id) { userErrors { field message } } } Query;
Hey @Jamessy,
To be sure I did some testing to confirm expected functionality of the Discount API, and using Insomnia had success with all attempts of the discountCodeDeactivate mutation. While not a seasoned PHP developer myself, you mentioned it likely being related to the variable ("id" input), and the shared request looks to be using ' '
instead of " "
- all documented examples I was able to find use the latter, so it could just be formatting.
Beyond that, if you are still consistently getting errors, opening an issue in the Github of library being used is going to be the best next step. Should you need, this is the recently released official Shopify PHP Library - GitHub and here are some third party libraries listed in our API resources.
- Cheers!
awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
You need to escape the $id with a "/".
$graphQL = <<<Query mutation discountCodeDeactivate(/$id: ID!) { discountCodeDeactivate(id: /$id) { userErrors { field message } } } Query;