Anchor to draftOrderCalculatedraft
draftOrderCalculate
mutation
Requires access scope.
Calculates the properties of a draft order. Useful for determining information such as total taxes or price without actually creating a draft order.
Anchor to Arguments
Arguments
- Anchor to inputinput•Draft
Order requiredInput! The fields for the draft order.
Was this section helpful?
Anchor to DraftOrderCalculatePayload returnsDraftOrderCalculatePayload returns
- Anchor to calculatedDraftOrdercalculated•
Draft Order The calculated properties for a draft order.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Calculate properties of a draft order
- Calculate properties of a draft order with markets context
- Calculating a draft order with no line items
- draftOrderCalculate reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CalculateDraftOrder($input: DraftOrderInput!) {
draftOrderCalculate(input: $input) {
calculatedDraftOrder {
customer {
id
email
firstName
numberOfOrders
defaultAddress {
id
firstName
lastName
address1
address2
city
provinceCode
zip
countryCodeV2
}
taxExempt
}
billingAddressMatchesShippingAddress
totalPriceSet {
mutation CalculateDraftOrder($input: DraftOrderInput!) {
draftOrderCalculate(input: $input) {
calculatedDraftOrder {
customer {
id
email
firstName
numberOfOrders
defaultAddress {
id
firstName
lastName
address1
address2
city
provinceCode
zip
countryCodeV2
}
taxExempt
}
billingAddressMatchesShippingAddress
totalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
lineItems {
appliedDiscount {
amountSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
value
valueType
description
}
discountedTotalSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
product {
id
title
}
quantity
requiresShipping
sku
taxable
title
variantTitle
variant {
id
}
weight {
value
unit
}
}
totalTaxSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
totalDiscountsSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
shippingLine {
id
custom
shippingRateHandle
title
originalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
}
presentmentCurrencyCode
}
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 CalculateDraftOrder($input: DraftOrderInput!) { draftOrderCalculate(input: $input) { calculatedDraftOrder { customer { id email firstName numberOfOrders defaultAddress { id firstName lastName address1 address2 city provinceCode zip countryCodeV2 } taxExempt } billingAddressMatchesShippingAddress totalPriceSet { presentmentMoney { amount currencyCode } shopMoney { amount currencyCode } } lineItems { appliedDiscount { amountSet { presentmentMoney { amount currencyCode } shopMoney { amount currencyCode } } value valueType description } discountedTotalSet { presentmentMoney { amount currencyCode } shopMoney { amount currencyCode } } product { id title } quantity requiresShipping sku taxable title variantTitle variant { id } weight { value unit } } totalTaxSet { presentmentMoney { amount currencyCode } shopMoney { amount currencyCode } } totalDiscountsSet { presentmentMoney { amount currencyCode } shopMoney { amount currencyCode } } shippingLine { id custom shippingRateHandle title originalPriceSet { presentmentMoney { amount currencyCode } shopMoney { amount currencyCode } } } presentmentCurrencyCode } userErrors { field message } } }",
"variables": {
"input": {
"appliedDiscount": {
"description": "Loyalty",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"billingAddress": {
"address1": "123 Amoebobacterieae St",
"address2": "",
"city": "Ottawa",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Bobsen",
"phone": "",
"provinceCode": "ON",
"zip": "K2P0V6"
},
"customerId": "gid://shopify/Customer/544365967",
"lineItems": [
{
"appliedDiscount": {
"description": "Promo",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"customAttributes": [],
"originalUnitPrice": 10,
"quantity": 1,
"requiresShipping": true,
"sku": "draft-151",
"taxable": true,
"title": "151cm",
"variantId": "gid://shopify/ProductVariant/43729076",
"weight": {
"unit": "KILOGRAMS",
"value": 1
}
},
{
"appliedDiscount": null,
"customAttributes": [],
"originalUnitPrice": "10.0",
"quantity": 2,
"requiresShipping": true,
"sku": null,
"taxable": true,
"title": "Spring Promo Item",
"variantId": null,
"weight": {
"unit": "KILOGRAMS",
"value": 1.2
}
}
],
"presentmentCurrencyCode": "CAD",
"shippingAddress": {
"address1": "",
"address2": "",
"city": "",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Smith",
"phone": "",
"provinceCode": "AB",
"zip": ""
},
"shippingLine": {
"price": "0.0",
"title": "Free shipping"
},
"taxExempt": false
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CalculateDraftOrder($input: DraftOrderInput!) {
draftOrderCalculate(input: $input) {
calculatedDraftOrder {
customer {
id
email
firstName
numberOfOrders
defaultAddress {
id
firstName
lastName
address1
address2
city
provinceCode
zip
countryCodeV2
}
taxExempt
}
billingAddressMatchesShippingAddress
totalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
lineItems {
appliedDiscount {
amountSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
value
valueType
description
}
discountedTotalSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
product {
id
title
}
quantity
requiresShipping
sku
taxable
title
variantTitle
variant {
id
}
weight {
value
unit
}
}
totalTaxSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
totalDiscountsSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
shippingLine {
id
custom
shippingRateHandle
title
originalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
}
presentmentCurrencyCode
}
userErrors {
field
message
}
}
}`,
{
variables: {
"input": {
"appliedDiscount": {
"description": "Loyalty",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"billingAddress": {
"address1": "123 Amoebobacterieae St",
"address2": "",
"city": "Ottawa",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Bobsen",
"phone": "",
"provinceCode": "ON",
"zip": "K2P0V6"
},
"customerId": "gid://shopify/Customer/544365967",
"lineItems": [
{
"appliedDiscount": {
"description": "Promo",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"customAttributes": [],
"originalUnitPrice": 10,
"quantity": 1,
"requiresShipping": true,
"sku": "draft-151",
"taxable": true,
"title": "151cm",
"variantId": "gid://shopify/ProductVariant/43729076",
"weight": {
"unit": "KILOGRAMS",
"value": 1
}
},
{
"appliedDiscount": null,
"customAttributes": [],
"originalUnitPrice": "10.0",
"quantity": 2,
"requiresShipping": true,
"sku": null,
"taxable": true,
"title": "Spring Promo Item",
"variantId": null,
"weight": {
"unit": "KILOGRAMS",
"value": 1.2
}
}
],
"presentmentCurrencyCode": "CAD",
"shippingAddress": {
"address1": "",
"address2": "",
"city": "",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Smith",
"phone": "",
"provinceCode": "AB",
"zip": ""
},
"shippingLine": {
"price": "0.0",
"title": "Free shipping"
},
"taxExempt": false
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CalculateDraftOrder($input: DraftOrderInput!) {
draftOrderCalculate(input: $input) {
calculatedDraftOrder {
customer {
id
email
firstName
numberOfOrders
defaultAddress {
id
firstName
lastName
address1
address2
city
provinceCode
zip
countryCodeV2
}
taxExempt
}
billingAddressMatchesShippingAddress
totalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
lineItems {
appliedDiscount {
amountSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
value
valueType
description
}
discountedTotalSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
product {
id
title
}
quantity
requiresShipping
sku
taxable
title
variantTitle
variant {
id
}
weight {
value
unit
}
}
totalTaxSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
totalDiscountsSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
shippingLine {
id
custom
shippingRateHandle
title
originalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
}
presentmentCurrencyCode
}
userErrors {
field
message
}
}
}`,
"variables": {
"input": {
"appliedDiscount": {
"description": "Loyalty",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"billingAddress": {
"address1": "123 Amoebobacterieae St",
"address2": "",
"city": "Ottawa",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Bobsen",
"phone": "",
"provinceCode": "ON",
"zip": "K2P0V6"
},
"customerId": "gid://shopify/Customer/544365967",
"lineItems": [
{
"appliedDiscount": {
"description": "Promo",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"customAttributes": [],
"originalUnitPrice": 10,
"quantity": 1,
"requiresShipping": true,
"sku": "draft-151",
"taxable": true,
"title": "151cm",
"variantId": "gid://shopify/ProductVariant/43729076",
"weight": {
"unit": "KILOGRAMS",
"value": 1
}
},
{
"appliedDiscount": null,
"customAttributes": [],
"originalUnitPrice": "10.0",
"quantity": 2,
"requiresShipping": true,
"sku": null,
"taxable": true,
"title": "Spring Promo Item",
"variantId": null,
"weight": {
"unit": "KILOGRAMS",
"value": 1.2
}
}
],
"presentmentCurrencyCode": "CAD",
"shippingAddress": {
"address1": "",
"address2": "",
"city": "",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Smith",
"phone": "",
"provinceCode": "AB",
"zip": ""
},
"shippingLine": {
"price": "0.0",
"title": "Free shipping"
},
"taxExempt": false
}
},
},
});
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 CalculateDraftOrder($input: DraftOrderInput!) {
draftOrderCalculate(input: $input) {
calculatedDraftOrder {
customer {
id
email
firstName
numberOfOrders
defaultAddress {
id
firstName
lastName
address1
address2
city
provinceCode
zip
countryCodeV2
}
taxExempt
}
billingAddressMatchesShippingAddress
totalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
lineItems {
appliedDiscount {
amountSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
value
valueType
description
}
discountedTotalSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
product {
id
title
}
quantity
requiresShipping
sku
taxable
title
variantTitle
variant {
id
}
weight {
value
unit
}
}
totalTaxSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
totalDiscountsSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
shippingLine {
id
custom
shippingRateHandle
title
originalPriceSet {
presentmentMoney {
amount
currencyCode
}
shopMoney {
amount
currencyCode
}
}
}
presentmentCurrencyCode
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"input": {
"appliedDiscount": {
"description": "Loyalty",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"billingAddress": {
"address1": "123 Amoebobacterieae St",
"address2": "",
"city": "Ottawa",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Bobsen",
"phone": "",
"provinceCode": "ON",
"zip": "K2P0V6"
},
"customerId": "gid://shopify/Customer/544365967",
"lineItems": [{"appliedDiscount"=>{"description"=>"Promo", "value"=>5, "valueType"=>"FIXED_AMOUNT"}, "customAttributes"=>[], "originalUnitPrice"=>10, "quantity"=>1, "requiresShipping"=>true, "sku"=>"draft-151", "taxable"=>true, "title"=>"151cm", "variantId"=>"gid://shopify/ProductVariant/43729076", "weight"=>{"unit"=>"KILOGRAMS", "value"=>1}}, {"appliedDiscount"=>nil, "customAttributes"=>[], "originalUnitPrice"=>"10.0", "quantity"=>2, "requiresShipping"=>true, "sku"=>nil, "taxable"=>true, "title"=>"Spring Promo Item", "variantId"=>nil, "weight"=>{"unit"=>"KILOGRAMS", "value"=>1.2}}],
"presentmentCurrencyCode": "CAD",
"shippingAddress": {
"address1": "",
"address2": "",
"city": "",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Smith",
"phone": "",
"provinceCode": "AB",
"zip": ""
},
"shippingLine": {
"price": "0.0",
"title": "Free shipping"
},
"taxExempt": false
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"input": {
"appliedDiscount": {
"description": "Loyalty",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"billingAddress": {
"address1": "123 Amoebobacterieae St",
"address2": "",
"city": "Ottawa",
"company": "",
"countryCode": "CA",
"firstName": "Bob",
"lastName": "Bobsen",
"phone": "",
"provinceCode": "ON",
"zip": "K2P0V6"
},
"customerId": "gid://shopify/Customer/544365967",
"lineItems": [
{
"appliedDiscount": {
"description": "Promo",
"value": 5,
"valueType": "FIXED_AMOUNT"
},
"customAttributes": [],
Response
JSON{
"draftOrderCalculate": {
"calculatedDraftOrder": {
"customer": {
"id": "gid://shopify/Customer/544365967",
"email": "bob@example.com",
"firstName": "Bob",
"numberOfOrders": "25",
"defaultAddress": {
"id": "gid://shopify/MailingAddress/544365967?model_name=CustomerAddress",
"firstName": "Bob",
"lastName": "Bobsen",
"address1": "123 Amoebobacterieae St",
"address2": "",
"city": "Ottawa",
"provinceCode": "ON",
"zip": "K2P0V6",
"countryCodeV2": "CA"
},
"taxExempt": false
},
"billingAddressMatchesShippingAddress": false,