Field 'appSubscription' doesn't exist on type 'QueryRoot'

Field 'appSubscription' doesn't exist on type 'QueryRoot'

Girish_Rajwani
Shopify Partner
88 3 10

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.

 

Girish | Shopify Expert  
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - My Shopify Apps: App Store | Looking for a solution to a problem in your store? Send me an email

Reply 1 (1)

amarudinanung
Shopify Partner
1 0 0

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);
    }