Skip to main content
Glama

complete-draft-order

Complete a Shopify draft order by specifying the draft order ID and variant ID. Ensures accurate order finalization within the Shopify Update MCP Server.

Instructions

Complete a draft order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
draftOrderIdYesID of the draft order to complete
variantIdYesID of the variant in the draft order

Implementation Reference

  • src/index.ts:484-509 (registration)
    MCP tool registration for 'complete-draft-order', including input schema (Zod), description, and thin handler that delegates to ShopifyClient.completeDraftOrder
    server.tool( "complete-draft-order", "Complete a draft order", { draftOrderId: z.string().describe("ID of the draft order to complete"), variantId: z.string().describe("ID of the variant in the draft order"), }, async ({ draftOrderId, variantId }) => { const client = new ShopifyClient(); try { const completedOrder = await client.completeDraftOrder( SHOPIFY_ACCESS_TOKEN, MYSHOPIFY_DOMAIN, draftOrderId, variantId ); return { content: [ { type: "text", text: JSON.stringify(completedOrder, null, 2) }, ], }; } catch (error) { return handleError("Failed to complete draft order", error); } } );
  • Input schema using Zod for tool parameters: draftOrderId and variantId
    { draftOrderId: z.string().describe("ID of the draft order to complete"), variantId: z.string().describe("ID of the variant in the draft order"), },
  • MCP tool handler function that instantiates ShopifyClient and calls completeDraftOrder, returning JSON response or error
    async ({ draftOrderId, variantId }) => { const client = new ShopifyClient(); try { const completedOrder = await client.completeDraftOrder( SHOPIFY_ACCESS_TOKEN, MYSHOPIFY_DOMAIN, draftOrderId, variantId ); return { content: [ { type: "text", text: JSON.stringify(completedOrder, null, 2) }, ], }; } catch (error) { return handleError("Failed to complete draft order", error); } }
  • Core implementation in ShopifyClient: validates variant availability, executes GraphQL draftOrderComplete mutation, handles errors, returns order details
    async completeDraftOrder( accessToken: string, shop: string, draftOrderId: string, variantId: string ): Promise<CompleteDraftOrderResponse> { // First, load the variant to check if it's available for sale const variantResult = await this.loadVariantsByIds(accessToken, shop, [ variantId, ]); if (!variantResult.variants || variantResult.variants.length === 0) { throw new ShopifyProductVariantNotFoundError({ contextData: { shop, variantId, }, }); } const variant = variantResult.variants[0]; if (!variant.availableForSale) { throw new ShopifyProductVariantNotAvailableForSaleError({ contextData: { shop, variantId, }, }); } const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop); const graphqlQuery = gql` mutation draftOrderComplete($id: ID!) { draftOrderComplete(id: $id) { draftOrder { id name order { id } } userErrors { field message } } } `; const res = await this.shopifyGraphqlRequest<{ data: { draftOrderComplete: { draftOrder: { id: string; name: string; order: { id: string; }; }; userErrors: Array<{ field: string[]; message: string; }>; }; }; }>({ url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`, accessToken, query: graphqlQuery, variables: { id: draftOrderId, }, }); const draftOrder = res.data.data.draftOrderComplete.draftOrder; const order = draftOrder.order; const userErrors = res.data.data.draftOrderComplete.userErrors; if (userErrors && userErrors.length > 0) { throw getGraphqlShopifyUserError(userErrors, { shop, draftOrderId, variantId, }); } return { draftOrderId: draftOrder.id, orderId: order.id, draftOrderName: draftOrder.name, }; }

Other Tools

Related 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/smithery-ai/shopify-mcp-server-main-1'

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