Anchor to subscriptionContractCreatesubscription
subscription Contract Create
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 Create Input!required The properties of the new Subscription Contract.
Was this section helpful?
- Anchor to draftdraft•
The Subscription Contract object.
- Anchor to userErrorsuser•
Errors [SubscriptionDraft User Error!]!non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {6 subscriptionContractCreate(input: $input) {7 draft {8 id9 }10 userErrors {11 field12 message13 }14 }15 }`,16 {17 variables: {18 "input": {19 "customerId": "gid://shopify/Customer/544365967",20 "currencyCode": "USD",21 "nextBillingDate": "2024-10-11T21:11:01-04:00",22 "contract": {23 "status": "ACTIVE",24 "note": "Note of a thing.",25 "customAttributes": [26 {27 "key": "Test",28 "value": "Test value"29 }30 ],31 "paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",32 "billingPolicy": {33 "minCycles": 3,34 "maxCycles": 12,35 "intervalCount": 1,36 "interval": "MONTH",37 "anchors": [38 {39 "type": "MONTHDAY",40 "day": 1241 }42 ]43 },44 "deliveryPolicy": {45 "intervalCount": 1,46 "interval": "MONTH",47 "anchors": [48 {49 "type": "MONTHDAY",50 "day": 1351 }52 ]53 },54 "deliveryPrice": 2.99,55 "deliveryMethod": {56 "shipping": {57 "address": {58 "firstName": "Mont",59 "lastName": "Réal",60 "address1": "490 Rue De La Gauchetière O",61 "country": "Canada",62 "province": "Québec",63 "phone": "+16135551212",64 "zip": "H2Z 0B3",65 "city": "Montréal"66 },67 "shippingOption": {68 "title": "Subscription shipping",69 "presentmentTitle": "Translated shipping for subscription",70 "description": "5-7 Days",71 "code": "GROUND",72 "carrierServiceId": null73 }74 }75 }76 }77 }78 },79 },80);8182const data = await response.json();83
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
JSON1{2 "input": {3 "customerId": "gid://shopify/Customer/544365967",4 "currencyCode": "USD",5 "nextBillingDate": "2024-10-11T21:11:01-04:00",6 "contract": {7 "status": "ACTIVE",8 "note": "Note of a thing.",9 "customAttributes": [10 {11 "key": "Test",12 "value": "Test value"13 }14 ],15 "paymentMethodId": "gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff",16 "billingPolicy": {17 "minCycles": 3,18 "maxCycles": 12,19 "intervalCount": 1,20 "interval": "MONTH",21 "anchors": [22 {23 "type": "MONTHDAY",24 "day": 1225 }26 ]27 },28 "deliveryPolicy": {29 "intervalCount": 1,30 "interval": "MONTH",31 "anchors": [32 {33 "type": "MONTHDAY",34 "day": 1335 }36 ]37 },38 "deliveryPrice": 2.99,39 "deliveryMethod": {40 "shipping": {41 "address": {42 "firstName": "Mont",43 "lastName": "Réal",44 "address1": "490 Rue De La Gauchetière O",45 "country": "Canada",46 "province": "Québec",47 "phone": "+16135551212",48 "zip": "H2Z 0B3",49 "city": "Montréal"50 },51 "shippingOption": {52 "title": "Subscription shipping",53 "presentmentTitle": "Translated shipping for subscription",54 "description": "5-7 Days",55 "code": "GROUND",56 "carrierServiceId": null57 }58 }59 }60 }61 }62}
Response
JSON1{2 "subscriptionContractCreate": {3 "draft": {4 "id": "gid://shopify/SubscriptionDraft/1055577422"5 },6 "userErrors": []7 }8}