mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {
subscriptionContractCreate(input: $input) {
draft {
id
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-04/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)