Skip to main content
Glama

create_draft_order

Create an editable Shopify draft order (cart/quote) with catalog variants or custom line items. Optionally assign a customer, email, note, tags, or copy default address. Returns draft GID and an invoice URL for payment.

Instructions

Create a new draft order — Shopify's term for an editable cart/quote not yet placed as an order. Each line item is EITHER a variant reference (variantId + quantity) for catalog products, OR a custom item (title + originalUnitPrice + quantity) for one-off charges or services not in the catalog. Optionally attach a customer, email, internal note, tags, and choose whether to copy the customer's default address. Returns the new draft's GID and an invoice URL the customer can use to pay. Drafts stay OPEN until you call complete_draft_order or send the invoice.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lineItemsYesAt least one line item. Each item is EITHER a variant reference (just variantId + quantity) OR a custom item (title + originalUnitPrice + quantity, no variantId). Mixing both shapes in one item is rejected by the refine() validator.
customerIdNoGID of an existing customer to attach to the draft. Get one from list_customers. Optional — drafts can be customer-less and converted to a guest checkout.
emailNoEmail address for the order. Useful when you don't have a customer record yet but want to email the invoice URL.
noteNoInternal note visible to staff only (not the customer).
tagsNoTags to apply to the draft for filtering/segmentation.
useCustomerDefaultAddressNoIf true and customerId is set, copy the customer's default shipping address onto the draft.

Implementation Reference

  • The async handler function for 'create_draft_order'. It builds the input object from args, calls the Shopify GraphQL mutation (CREATE_DRAFT_ORDER_MUTATION), checks for user errors, and returns a formatted response with the draft order name, ID, total, and invoice URL.
      async (args) => {
        const input: Record<string, unknown> = {
          lineItems: mapLineItemsForInput(args.lineItems),
        };
        if (args.customerId) input.customerId = args.customerId;
        if (args.email) input.email = args.email;
        if (args.note) input.note = args.note;
        if (args.tags) input.tags = args.tags;
        if (args.useCustomerDefaultAddress !== undefined) {
          input.useCustomerDefaultAddress = args.useCustomerDefaultAddress;
        }
    
        const data = await client.graphql<{
          draftOrderCreate: {
            draftOrder: DraftOrder | null;
            userErrors: ShopifyUserError[];
          };
        }>(CREATE_DRAFT_ORDER_MUTATION, { input });
        throwIfUserErrors(data.draftOrderCreate.userErrors, "draftOrderCreate");
        const d = data.draftOrderCreate.draftOrder;
        if (!d) {
          return {
            content: [
              { type: "text" as const, text: "draftOrderCreate returned no draft order." },
            ],
          };
        }
        const total = `${d.totalPriceSet.shopMoney.amount} ${d.totalPriceSet.shopMoney.currencyCode}`;
        return {
          content: [
            {
              type: "text" as const,
              text: [
                `Created draft order ${d.name} [${d.status}]`,
                `  ID: ${d.id}`,
                `  Total: ${total}`,
                d.invoiceUrl ? `  Invoice: ${d.invoiceUrl}` : "",
              ]
                .filter(Boolean)
                .join("\n"),
            },
          ],
        };
      },
    );
  • The Zod-based input schema for 'create_draft_order'. Defines parameters: lineItems (array with variantId or custom item), customerId, email, note, tags, useCustomerDefaultAddress.
    const createDraftOrderSchema = {
      lineItems: z
        .array(lineItemSchema)
        .min(1)
        .describe(
          "At least one line item. Each item is EITHER a variant reference (just variantId + quantity) OR a custom item (title + originalUnitPrice + quantity, no variantId). Mixing both shapes in one item is rejected by the refine() validator.",
        ),
      customerId: z
        .string()
        .optional()
        .describe(
          "GID of an existing customer to attach to the draft. Get one from list_customers. Optional — drafts can be customer-less and converted to a guest checkout.",
        ),
      email: z
        .string()
        .email()
        .optional()
        .describe(
          "Email address for the order. Useful when you don't have a customer record yet but want to email the invoice URL.",
        ),
      note: z
        .string()
        .optional()
        .describe("Internal note visible to staff only (not the customer)."),
      tags: z
        .array(z.string())
        .optional()
        .describe("Tags to apply to the draft for filtering/segmentation."),
      useCustomerDefaultAddress: z
        .boolean()
        .optional()
        .describe(
          "If true and customerId is set, copy the customer's default shipping address onto the draft.",
        ),
    };
  • The registration of 'create_draft_order' via server.tool() in the registerDraftOrderTools function. It binds the tool name, description, schema, and handler.
      server.tool(
      "create_draft_order",
      "Create a new draft order — Shopify's term for an editable cart/quote not yet placed as an order. Each line item is EITHER a variant reference (variantId + quantity) for catalog products, OR a custom item (title + originalUnitPrice + quantity) for one-off charges or services not in the catalog. Optionally attach a customer, email, internal note, tags, and choose whether to copy the customer's default address. Returns the new draft's GID and an invoice URL the customer can use to pay. Drafts stay OPEN until you call complete_draft_order or send the invoice.",
      createDraftOrderSchema,
      async (args) => {
        const input: Record<string, unknown> = {
          lineItems: mapLineItemsForInput(args.lineItems),
        };
        if (args.customerId) input.customerId = args.customerId;
        if (args.email) input.email = args.email;
        if (args.note) input.note = args.note;
        if (args.tags) input.tags = args.tags;
        if (args.useCustomerDefaultAddress !== undefined) {
          input.useCustomerDefaultAddress = args.useCustomerDefaultAddress;
        }
    
        const data = await client.graphql<{
          draftOrderCreate: {
            draftOrder: DraftOrder | null;
            userErrors: ShopifyUserError[];
          };
        }>(CREATE_DRAFT_ORDER_MUTATION, { input });
        throwIfUserErrors(data.draftOrderCreate.userErrors, "draftOrderCreate");
        const d = data.draftOrderCreate.draftOrder;
        if (!d) {
          return {
            content: [
              { type: "text" as const, text: "draftOrderCreate returned no draft order." },
            ],
          };
        }
        const total = `${d.totalPriceSet.shopMoney.amount} ${d.totalPriceSet.shopMoney.currencyCode}`;
        return {
          content: [
            {
              type: "text" as const,
              text: [
                `Created draft order ${d.name} [${d.status}]`,
                `  ID: ${d.id}`,
                `  Total: ${total}`,
                d.invoiceUrl ? `  Invoice: ${d.invoiceUrl}` : "",
              ]
                .filter(Boolean)
                .join("\n"),
            },
          ],
        };
      },
    );
  • The GraphQL mutation string used by the handler to create a draft order via Shopify's Admin API (draftOrderCreate).
    const CREATE_DRAFT_ORDER_MUTATION = /* GraphQL */ `
      mutation DraftOrderCreate($input: DraftOrderInput!) {
        draftOrderCreate(input: $input) {
          draftOrder {
            id
            name
            status
            invoiceUrl
            totalPriceSet { shopMoney { amount currencyCode } }
          }
          userErrors { field message }
        }
      }
    `;
  • Helper function mapLineItemsForInput that maps line items from Zod-inferred types to Shopify API input format, handling both variant references and custom items.
    function mapLineItemsForInput(
      items: z.infer<typeof lineItemSchema>[] | undefined,
    ):
      | Array<{
          variantId?: string;
          quantity: number;
          title?: string;
          originalUnitPrice?: string;
        }>
      | undefined {
      if (!items) return undefined;
      return items.map((li) => {
        if (li.variantId) {
          return { variantId: li.variantId, quantity: li.quantity };
        }
        return {
          title: li.title!,
          quantity: li.quantity,
          originalUnitPrice: li.originalUnitPrice!,
        };
      });
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Describes draft lifecycle (stays open until complete_draft_order or invoice), return value (GID and invoice URL), and line item constraints. Does not mention auth or rate limits, but those are less critical for a creation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Moderately sized paragraph with front-loaded purpose. Each sentence adds value, but could be slightly more concise. Structure is logical: purpose, line items, optional fields, return, lifecycle.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, description mentions return values. All 6 parameters are described with usage context. Behavioral context (draft lifecycle, line item constraints) is well covered for a creation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, baseline 3. Description adds significant value by explaining the two exclusive line item shapes (variant vs custom) and required fields for each, beyond what schema descriptions provide.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the tool creates a draft order (a Shopify editable cart/quote), distinguishes it from sibling tools like complete_draft_order, get_draft_order, etc. Provides specific verb and resource with context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explains when to use variant vs custom line items, mentions optional customer, email, note, tags, and notes that drafts stay open until completion. Does not explicitly state when not to use, but the purpose is clear enough.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/miller-joe/shopify-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server