Hi all,
i am using 2024-10 API version and trying fetch charge status but getting below error.
Error: Field ‘appSubscription’ doesn’t exist on type ‘QueryRoot’. Below is the code
const response = await admin.graphql(
#graphql query GetChargeStatus { appSubscription(id: $chargeId) { id status } },
{
“variables”: {
“id”: gid://shopify/AppSubscription/${charge_id}
}
}
);
Any help would be really appreciated.
This works for me in PHP
public function getRecurringCharge() {
$shop_url = ‘your-shop-name.myshopify.com’;
$access_token = ‘your-access-token’;
$encodedId = base64_encode(“gid://shopify/AppSubscription/28125626551”);
$query = <<<QUERY
{
node(id: “$encodedId”) {
… on AppSubscription {
id
name
status
currentPeriodEnd
test
trialDays
createdAt
returnUrl
lineItems {
id
}
}
}
}
QUERY;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => “https://$shop_url/admin/api/2025-01/graphql.json”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_HTTPHEADER => [
‘Content-Type: application/json’,
“X-Shopify-Access-Token: $access_token”,
],
CURLOPT_POSTFIELDS => json_encode([‘query’ => $query])
]);
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
if ($error) {
throw new Exception(“cURL Error: $error”);
}
return json_decode($response, true);
}