Anchor to subscriptionContractCreatesubscription
subscriptionContractCreate
mutation
Requires access scope. Also: The user must have manage_orders_information permission.
Creates a Subscription Contract Draft. You can submit all the desired information for the draft using Subscription Draft Input object. You can also update the draft using the Subscription Contract Update mutation. The draft is not saved until you call the Subscription Draft Commit mutation.
Anchor to Arguments
Arguments
- Anchor to inputinput•Subscription
Contract requiredCreate Input! The properties of the new Subscription Contract.
Was this section helpful?
Anchor to SubscriptionContractCreatePayload returnsSubscriptionContractCreatePayload returns
- Anchor to draftdraft•
The Subscription Contract object.
- Anchor to userErrorsuser•
Errors [SubscriptionDraft non-nullUser Error!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a subscription contract with draft input
- subscriptionContractCreate reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {
subscriptionContractCreate(input: $input) {
draft {
id
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"currencyCode": "USD",
"nextBillingDate": "2024-10-11T21:11:01-04:00",
"contract": {
"status": "ACTIVE",
"note": "Note of a thing.",
"customAttributes": [
{
"key": "Test",
"value": "Test value"
mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {
subscriptionContractCreate(input: $input) {
draft {
id
}
userErrors {
field
message
}
}
}
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 createSubscriptionContract($input: SubscriptionContractCreateInput!) { subscriptionContractCreate(input: $input) { draft { id } userErrors { field message } } }",
"variables": {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"currencyCode": "USD",
"nextBillingDate": "2024-10-11T21:11:01-04:00",
"contract": {
"status": "ACTIVE",
"note": "Note of a thing.",
"customAttributes": [
{
"key": "Test",
"value": "Test value"
}
],
"paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",
"billingPolicy": {
"minCycles": 3,
"maxCycles": 12,
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 12
}
]
},
"deliveryPolicy": {
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 13
}
]
},
"deliveryPrice": 2.99,
"deliveryMethod": {
"shipping": {
"address": {
"firstName": "Mont",
"lastName": "Réal",
"address1": "490 Rue De La Gauchetière O",
"country": "Canada",
"province": "Québec",
"phone": "+16135551212",
"zip": "H2Z 0B3",
"city": "Montréal"
},
"shippingOption": {
"title": "Subscription shipping",
"presentmentTitle": "Translated shipping for subscription",
"description": "5-7 Days",
"code": "GROUND",
"carrierServiceId": null
}
}
}
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {
subscriptionContractCreate(input: $input) {
draft {
id
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"currencyCode": "USD",
"nextBillingDate": "2024-10-11T21:11:01-04:00",
"contract": {
"status": "ACTIVE",
"note": "Note of a thing.",
"customAttributes": [
{
"key": "Test",
"value": "Test value"
}
],
"paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",
"billingPolicy": {
"minCycles": 3,
"maxCycles": 12,
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 12
}
]
},
"deliveryPolicy": {
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 13
}
]
},
"deliveryPrice": 2.99,
"deliveryMethod": {
"shipping": {
"address": {
"firstName": "Mont",
"lastName": "Réal",
"address1": "490 Rue De La Gauchetière O",
"country": "Canada",
"province": "Québec",
"phone": "+16135551212",
"zip": "H2Z 0B3",
"city": "Montréal"
},
"shippingOption": {
"title": "Subscription shipping",
"presentmentTitle": "Translated shipping for subscription",
"description": "5-7 Days",
"code": "GROUND",
"carrierServiceId": null
}
}
}
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {
subscriptionContractCreate(input: $input) {
draft {
id
}
userErrors {
field
message
}
}
}`,
"variables": {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"currencyCode": "USD",
"nextBillingDate": "2024-10-11T21:11:01-04:00",
"contract": {
"status": "ACTIVE",
"note": "Note of a thing.",
"customAttributes": [
{
"key": "Test",
"value": "Test value"
}
],
"paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",
"billingPolicy": {
"minCycles": 3,
"maxCycles": 12,
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 12
}
]
},
"deliveryPolicy": {
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 13
}
]
},
"deliveryPrice": 2.99,
"deliveryMethod": {
"shipping": {
"address": {
"firstName": "Mont",
"lastName": "Réal",
"address1": "490 Rue De La Gauchetière O",
"country": "Canada",
"province": "Québec",
"phone": "+16135551212",
"zip": "H2Z 0B3",
"city": "Montréal"
},
"shippingOption": {
"title": "Subscription shipping",
"presentmentTitle": "Translated shipping for subscription",
"description": "5-7 Days",
"code": "GROUND",
"carrierServiceId": null
}
}
}
}
}
},
},
});
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 createSubscriptionContract($input: SubscriptionContractCreateInput!) {
subscriptionContractCreate(input: $input) {
draft {
id
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"currencyCode": "USD",
"nextBillingDate": "2024-10-11T21:11:01-04:00",
"contract": {
"status": "ACTIVE",
"note": "Note of a thing.",
"customAttributes": [{"key"=>"Test", "value"=>"Test value"}],
"paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",
"billingPolicy": {
"minCycles": 3,
"maxCycles": 12,
"intervalCount": 1,
"interval": "MONTH",
"anchors": [{"type"=>"MONTHDAY", "day"=>12}]
},
"deliveryPolicy": {
"intervalCount": 1,
"interval": "MONTH",
"anchors": [{"type"=>"MONTHDAY", "day"=>13}]
},
"deliveryPrice": 2.99,
"deliveryMethod": {
"shipping": {
"address": {
"firstName": "Mont",
"lastName": "Réal",
"address1": "490 Rue De La Gauchetière O",
"country": "Canada",
"province": "Québec",
"phone": "+16135551212",
"zip": "H2Z 0B3",
"city": "Montréal"
},
"shippingOption": {
"title": "Subscription shipping",
"presentmentTitle": "Translated shipping for subscription",
"description": "5-7 Days",
"code": "GROUND",
"carrierServiceId": null
}
}
}
}
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"input": {
"customerId": "gid://shopify/Customer/544365967",
"currencyCode": "USD",
"nextBillingDate": "2024-10-11T21:11:01-04:00",
"contract": {
"status": "ACTIVE",
"note": "Note of a thing.",
"customAttributes": [
{
"key": "Test",
"value": "Test value"
}
],
"paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",
"billingPolicy": {
"minCycles": 3,
"maxCycles": 12,
"intervalCount": 1,
"interval": "MONTH",
"anchors": [
{
"type": "MONTHDAY",
"day": 12
}
]
Response
JSON{
"subscriptionContractCreate": {
"draft": {
"id": "gid://shopify/SubscriptionDraft/1055577422"
},
"userErrors": []
}
}