subscription Contract Createmutation
mutation
2025-01release candidate
Requires
write_own_subscription_contracts
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.
Arguments
The properties of the new Subscription Contract.
Was this section helpful?
SubscriptionContractCreatePayload returns
The Subscription Contract object.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
Copy
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();
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)
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 } } } } } }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $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]);
Hide code
Input variables
Copy
{ "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 } } } } } }
Hide code
Response
JSON
{ "subscriptionContractCreate": { "draft": { "id": "gid://shopify/SubscriptionDraft/1055577422" }, "userErrors": [] } }