When I'm using the following mutation in GraphiQL App it works perfectly but when I run it using Postman or CURL it just doesn't work. This issue is happening for Function related mutations only.
The Mutation:
mutation {
discountAutomaticAppCreate(
automaticAppDiscount: {
title: "Volume Discount Created from APP 011",
functionId: "9d8aas8-78asd-8d7sa-86f0-dg789asdfa9sd",
startsAt: "2023-09-19T00:00:00"}
) {
# Payload
userErrors {
code
field
message
}
automaticAppDiscount {
discountId
title
status
createdAt
endsAt
}
}
}
The error that I get when using CURL or Postman:
"data": {
"discountAutomaticAppCreate": {
"userErrors": [
{
"code": "INVALID",
"field": [
"automaticAppDiscount",
"functionId"
],
"message": "Function not found."
}
],
"automaticAppDiscount": null
}
}
The Functions that I'm using to make the CURL request(Though it's not that important as this is just working fine for many other queries):
public function makeGraphqlApiRequest($data)
{
$storeName = 'store-name';
$apiVersion = '2023-07';
$accessToken = 'access-token';
$graphqlEndpoint = "https://$storeName.myshopify.com/admin/api/$apiVersion/graphql.json";
$headers = [
"Content-Type: application/json",
"X-Shopify-Access-Token: $accessToken"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $graphqlEndpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
return 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
return $response;
}
// End makeGraphqlApiRequest Method
Later I rechecked the "shop-name" and "api-version" both in GraphiQL and CURL, Postman. They all had same shop-name and api-version. What can I do to solve the problem? Thanks!