Anchor to section titled 'undefined'

draftOrderCreateFromOrder
mutation

Requires write_draft_orders access scope. Also: Requires write_orders access scope.

Creates a draft order from order.


Anchor to orderId
orderId
required

Specifies the order's id that we create the draft order from.


Was this section helpful?

The created draft order.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation DraftOrderCreateFromOrder($orderId: ID!) {
  draftOrderCreateFromOrder(orderId: $orderId) {
    draftOrder {
      id
    }
    userErrors {
      field
      message
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation DraftOrderCreateFromOrder($orderId: ID!) { draftOrderCreateFromOrder(orderId: $orderId) { draftOrder { id } userErrors { field message } } }",
 "variables": {
    "orderId": "gid://shopify/Order/148977776"
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation DraftOrderCreateFromOrder($orderId: ID!) {
    draftOrderCreateFromOrder(orderId: $orderId) {
      draftOrder {
        id
      }
      userErrors {
        field
        message
      }
    }
  }`,
  {
    variables: {
      "orderId": "gid://shopify/Order/148977776"
    },
  },
);

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 DraftOrderCreateFromOrder($orderId: ID!) {
    draftOrderCreateFromOrder(orderId: $orderId) {
      draftOrder {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY

variables = {
  "orderId": "gid://shopify/Order/148977776"
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation DraftOrderCreateFromOrder($orderId: ID!) {
      draftOrderCreateFromOrder(orderId: $orderId) {
        draftOrder {
          id
        }
        userErrors {
          field
          message
        }
      }
    }`,
    "variables": {
      "orderId": "gid://shopify/Order/148977776"
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation DraftOrderCreateFromOrder($orderId: ID!) {
    draftOrderCreateFromOrder(orderId: $orderId) {
      draftOrder {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "orderId" => "gid://shopify/Order/148977776",
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "orderId": "gid://shopify/Order/148977776"
}
Hide code
Response
JSON
{
  "draftOrderCreateFromOrder": {
    "draftOrder": {
      "id": "gid://shopify/DraftOrder/1069920479"
    },
    "userErrors": []
  }
}