Version: 2025-01
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) { subscriptionContractCreate(input: $input) { draft { id } userErrors { field message } } }\",\n \"variables\": {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"currencyCode\": \"USD\",\n \"nextBillingDate\": \"2024-10-11T21:11:01-04:00\",\n \"contract\": {\n \"status\": \"ACTIVE\",\n \"note\": \"Note of a thing.\",\n \"customAttributes\": [\n {\n \"key\": \"Test\",\n \"value\": \"Test value\"\n }\n ],\n \"paymentMethodId\": \"gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff\",\n \"billingPolicy\": {\n \"minCycles\": 3,\n \"maxCycles\": 12,\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [\n {\n \"type\": \"MONTHDAY\",\n \"day\": 12\n }\n ]\n },\n \"deliveryPolicy\": {\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [\n {\n \"type\": \"MONTHDAY\",\n \"day\": 13\n }\n ]\n },\n \"deliveryPrice\": 2.99,\n \"deliveryMethod\": {\n \"shipping\": {\n \"address\": {\n \"firstName\": \"Mont\",\n \"lastName\": \"Réal\",\n \"address1\": \"490 Rue De La Gauchetière O\",\n \"country\": \"Canada\",\n \"province\": \"Québec\",\n \"phone\": \"+16135551212\",\n \"zip\": \"H2Z 0B3\",\n \"city\": \"Montréal\"\n },\n \"shippingOption\": {\n \"title\": \"Subscription shipping\",\n \"presentmentTitle\": \"Translated shipping for subscription\",\n \"description\": \"5-7 Days\",\n \"code\": \"GROUND\",\n \"carrierServiceId\": null\n }\n }\n }\n }\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {\n subscriptionContractCreate(input: $input) {\n draft {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"currencyCode\": \"USD\",\n \"nextBillingDate\": \"2024-10-11T21:11:01-04:00\",\n \"contract\": {\n \"status\": \"ACTIVE\",\n \"note\": \"Note of a thing.\",\n \"customAttributes\": [\n {\n \"key\": \"Test\",\n \"value\": \"Test value\"\n }\n ],\n \"paymentMethodId\": \"gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff\",\n \"billingPolicy\": {\n \"minCycles\": 3,\n \"maxCycles\": 12,\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [\n {\n \"type\": \"MONTHDAY\",\n \"day\": 12\n }\n ]\n },\n \"deliveryPolicy\": {\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [\n {\n \"type\": \"MONTHDAY\",\n \"day\": 13\n }\n ]\n },\n \"deliveryPrice\": 2.99,\n \"deliveryMethod\": {\n \"shipping\": {\n \"address\": {\n \"firstName\": \"Mont\",\n \"lastName\": \"Réal\",\n \"address1\": \"490 Rue De La Gauchetière O\",\n \"country\": \"Canada\",\n \"province\": \"Québec\",\n \"phone\": \"+16135551212\",\n \"zip\": \"H2Z 0B3\",\n \"city\": \"Montréal\"\n },\n \"shippingOption\": {\n \"title\": \"Subscription shipping\",\n \"presentmentTitle\": \"Translated shipping for subscription\",\n \"description\": \"5-7 Days\",\n \"code\": \"GROUND\",\n \"carrierServiceId\": null\n }\n }\n }\n }\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {\n subscriptionContractCreate(input: $input) {\n draft {\n id\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"currencyCode\": \"USD\",\n \"nextBillingDate\": \"2024-10-11T21:11:01-04:00\",\n \"contract\": {\n \"status\": \"ACTIVE\",\n \"note\": \"Note of a thing.\",\n \"customAttributes\": [{\"key\"=>\"Test\", \"value\"=>\"Test value\"}],\n \"paymentMethodId\": \"gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff\",\n \"billingPolicy\": {\n \"minCycles\": 3,\n \"maxCycles\": 12,\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [{\"type\"=>\"MONTHDAY\", \"day\"=>12}]\n },\n \"deliveryPolicy\": {\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [{\"type\"=>\"MONTHDAY\", \"day\"=>13}]\n },\n \"deliveryPrice\": 2.99,\n \"deliveryMethod\": {\n \"shipping\": {\n \"address\": {\n \"firstName\": \"Mont\",\n \"lastName\": \"Réal\",\n \"address1\": \"490 Rue De La Gauchetière O\",\n \"country\": \"Canada\",\n \"province\": \"Québec\",\n \"phone\": \"+16135551212\",\n \"zip\": \"H2Z 0B3\",\n \"city\": \"Montréal\"\n },\n \"shippingOption\": {\n \"title\": \"Subscription shipping\",\n \"presentmentTitle\": \"Translated shipping for subscription\",\n \"description\": \"5-7 Days\",\n \"code\": \"GROUND\",\n \"carrierServiceId\": null\n }\n }\n }\n }\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {\n subscriptionContractCreate(input: $input) {\n draft {\n id\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"customerId\" => \"gid://shopify/Customer/544365967\",\n \"currencyCode\" => \"USD\",\n \"nextBillingDate\" => \"2024-10-11T21:11:01-04:00\",\n \"contract\" => [\n \"status\" => \"ACTIVE\",\n \"note\" => \"Note of a thing.\",\n \"customAttributes\" => [{\"key\"=>\"Test\", \"value\"=>\"Test value\"}],\n \"paymentMethodId\" => \"gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff\",\n \"billingPolicy\" => [\n \"minCycles\" => 3,\n \"maxCycles\" => 12,\n \"intervalCount\" => 1,\n \"interval\" => \"MONTH\",\n \"anchors\" => [{\"type\"=>\"MONTHDAY\", \"day\"=>12}],\n ],\n \"deliveryPolicy\" => [\n \"intervalCount\" => 1,\n \"interval\" => \"MONTH\",\n \"anchors\" => [{\"type\"=>\"MONTHDAY\", \"day\"=>13}],\n ],\n \"deliveryPrice\" => 2.99,\n \"deliveryMethod\" => [\n \"shipping\" => [\n \"address\" => [\n \"firstName\" => \"Mont\",\n \"lastName\" => \"Réal\",\n \"address1\" => \"490 Rue De La Gauchetière O\",\n \"country\" => \"Canada\",\n \"province\" => \"Québec\",\n \"phone\" => \"+16135551212\",\n \"zip\" => \"H2Z 0B3\",\n \"city\" => \"Montréal\",\n ],\n \"shippingOption\" => [\n \"title\" => \"Subscription shipping\",\n \"presentmentTitle\" => \"Translated shipping for subscription\",\n \"description\" => \"5-7 Days\",\n \"code\" => \"GROUND\",\n \"carrierServiceId\" => null,\n ],\n ],\n ],\n ],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {\n subscriptionContractCreate(input: $input) {\n draft {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"currencyCode\": \"USD\",\n \"nextBillingDate\": \"2024-10-11T21:11:01-04:00\",\n \"contract\": {\n \"status\": \"ACTIVE\",\n \"note\": \"Note of a thing.\",\n \"customAttributes\": [\n {\n \"key\": \"Test\",\n \"value\": \"Test value\"\n }\n ],\n \"paymentMethodId\": \"gid://shopify/CustomerPaymentMethod/b7cc6e3267aace169e516ed48be72dff\",\n \"billingPolicy\": {\n \"minCycles\": 3,\n \"maxCycles\": 12,\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [\n {\n \"type\": \"MONTHDAY\",\n \"day\": 12\n }\n ]\n },\n \"deliveryPolicy\": {\n \"intervalCount\": 1,\n \"interval\": \"MONTH\",\n \"anchors\": [\n {\n \"type\": \"MONTHDAY\",\n \"day\": 13\n }\n ]\n },\n \"deliveryPrice\": 2.99,\n \"deliveryMethod\": {\n \"shipping\": {\n \"address\": {\n \"firstName\": \"Mont\",\n \"lastName\": \"Réal\",\n \"address1\": \"490 Rue De La Gauchetière O\",\n \"country\": \"Canada\",\n \"province\": \"Québec\",\n \"phone\": \"+16135551212\",\n \"zip\": \"H2Z 0B3\",\n \"city\": \"Montréal\"\n },\n \"shippingOption\": {\n \"title\": \"Subscription shipping\",\n \"presentmentTitle\": \"Translated shipping for subscription\",\n \"description\": \"5-7 Days\",\n \"code\": \"GROUND\",\n \"carrierServiceId\": null\n }\n }\n }\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation createSubscriptionContract($input: SubscriptionContractCreateInput!) {\n subscriptionContractCreate(input: $input) {\n draft {\n id\n }\n userErrors {\n field\n message\n }\n }\n}"
input: { "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: { "data": { "subscriptionContractCreate": { "draft": { "id": "gid://shopify/SubscriptionDraft/1055577422" }, "userErrors": [] } } }