mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) {
appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) { appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) { userErrors { field message } appSubscription { id } confirmationUrl } }",
"variables": {
"name": "Super Duper Recurring Plan",
"returnUrl": "http://super-duper.shopifyapps.com/",
"lineItems": [
{
"plan": {
"appRecurringPricingDetails": {
"price": {
"amount": 10.0,
"currencyCode": "USD"
},
"interval": "EVERY_30_DAYS"
}
}
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) {
appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}`,
{
variables: {
"name": "Super Duper Recurring Plan",
"returnUrl": "http://super-duper.shopifyapps.com/",
"lineItems": [
{
"plan": {
"appRecurringPricingDetails": {
"price": {
"amount": 10.0,
"currencyCode": "USD"
},
"interval": "EVERY_30_DAYS"
}
}
}
]
},
},
);
const data = await response.json();
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) {
appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}
QUERY
variables = {
"name": "Super Duper Recurring Plan",
"returnUrl": "http://super-duper.shopifyapps.com/",
"lineItems": [{"plan"=>{"appRecurringPricingDetails"=>{"price"=>{"amount"=>10.0, "currencyCode"=>"USD"}, "interval"=>"EVERY_30_DAYS"}}}]
}
response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) {
appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}`,
"variables": {
"name": "Super Duper Recurring Plan",
"returnUrl": "http://super-duper.shopifyapps.com/",
"lineItems": [
{
"plan": {
"appRecurringPricingDetails": {
"price": {
"amount": 10.0,
"currencyCode": "USD"
},
"interval": "EVERY_30_DAYS"
}
}
}
]
},
},
});
use Shopify\Clients\Graphql;
$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
mutation AppSubscriptionCreate($name: String!, $lineItems: [AppSubscriptionLineItemInput!]!, $returnUrl: URL!) {
appSubscriptionCreate(name: $name, returnUrl: $returnUrl, lineItems: $lineItems) {
userErrors {
field
message
}
appSubscription {
id
}
confirmationUrl
}
}
QUERY;
$variables = [
"name" => "Super Duper Recurring Plan",
"returnUrl" => "http://super-duper.shopifyapps.com/",
"lineItems" => [{"plan"=>{"appRecurringPricingDetails"=>{"price"=>{"amount"=>10.0, "currencyCode"=>"USD"}, "interval"=>"EVERY_30_DAYS"}}}],
];
$response = $client->query(["query" => $query, "variables" => $variables]);