appSubscriptionCreate
Allows an app to charge a store for features or services on a recurring basis.
Arguments
- Anchor to lineItemsline•
Items [AppSubscription requiredLine Item Input!]! Attaches one or more pricing plans to an app subscription. Only one pricing plan can be defined for each available type.
- Anchor to namename•String!required
A descriptive name for the app subscription.
- Anchor to replacementBehaviorreplacement•
Behavior AppSubscription Default:STANDARDReplacement Behavior The replacement behavior when creating an app subscription for a merchant with an already existing app subscription.
- Anchor to returnUrlreturn•
Url URL!required The URL pointing to the page where the merchant is redirected after approving the app subscription.
- Anchor to testtest•BooleanDefault:false
Whether the app subscription is a test transaction.
- Anchor to trialDaystrial•
Days The number of days of the free trial period, beginning on the day that the merchant approves the app charges.
Anchor to AppSubscriptionCreatePayload returnsAppSubscriptionCreatePayload returns
- Anchor to appSubscriptionapp•
Subscription The newly-created app subscription.
- Anchor to confirmationUrlconfirmation•
Url The URL pointing to the page where the merchant approves or declines the charges for an app subscription.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Examples
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/2025-01/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"
}
}
}
]
},
},
});