Hello, first time using shopify (and GraphQL for that matter). We are looking to create a subscription for our app but the PHP code to initiate this is giving errors: https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/appSubscriptionCreate#examples-Create_a_subscription_with_a_free_trial_
use Shopify\Clients\Graphql;
$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!, $trialDays: Int) {
appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems, trialDays: $trialDays) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}
QUERY;
$variables = [
"name" => "Super Duper Recurring Plan with a Trial",
"returnUrl" => "http://super-duper.shopifyapps.com/",
"trialDays" => 7,
"lineItems" => [{"plan"=>{"appRecurringPricingDetails"=>{"price"=>{"amount"=>10.0, "currencyCode"=>"USD"}}}}],
];
$response = $client->query(["query" => $query, "variables" => $variables]);
“Parse error: syntax error, unexpected token “{”, expecting “]””
If I change the $variables to the following to match what I know as PHP’s style:
$variables = [
"name" => "Super Duper Recurring Plan with a Trial",
"returnUrl" => "http://super-duper.shopifyapps.com/",
"trialDays" => 7,
"lineItems" => ["plan"=> [
"appRecurringPricingDetails"=> [
"price"=>["amount"=>10.0, "currencyCode"=>"USD"]
]
]
]];
I now get undefined variables for $name etc, but my understanding of GraphQL is getting in the way.
Can anyone provide a working example? Running PHP 8.3