Anchor to draftOrderCalculatedraft
draft Order Calculate
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 Input!required The fields for the draft order.
Was this section helpful?
- 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?
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation CalculateDraftOrder($input: DraftOrderInput!) {6 draftOrderCalculate(input: $input) {7 calculatedDraftOrder {8 customer {9 id10 email11 firstName12 numberOfOrders13 defaultAddress {14 id15 firstName16 lastName17 address118 address219 city20 provinceCode21 zip22 countryCodeV223 }24 taxExempt25 }26 billingAddressMatchesShippingAddress27 totalPriceSet {28 presentmentMoney {29 amount30 currencyCode31 }32 shopMoney {33 amount34 currencyCode35 }36 }37 lineItems {38 appliedDiscount {39 amountSet {40 presentmentMoney {41 amount42 currencyCode43 }44 shopMoney {45 amount46 currencyCode47 }48 }49 value50 valueType51 description52 }53 discountedTotalSet {54 presentmentMoney {55 amount56 currencyCode57 }58 shopMoney {59 amount60 currencyCode61 }62 }63 product {64 id65 title66 }67 quantity68 requiresShipping69 sku70 taxable71 title72 variantTitle73 variant {74 id75 }76 weight {77 value78 unit79 }80 }81 totalTaxSet {82 presentmentMoney {83 amount84 currencyCode85 }86 shopMoney {87 amount88 currencyCode89 }90 }91 totalDiscountsSet {92 presentmentMoney {93 amount94 currencyCode95 }96 shopMoney {97 amount98 currencyCode99 }100 }101 shippingLine {102 id103 custom104 shippingRateHandle105 title106 originalPriceSet {107 presentmentMoney {108 amount109 currencyCode110 }111 shopMoney {112 amount113 currencyCode114 }115 }116 }117 presentmentCurrencyCode118 }119 userErrors {120 field121 message122 }123 }124 }`,125 {126 variables: {127 "input": {128 "appliedDiscount": {129 "description": "Loyalty",130 "value": 5,131 "valueType": "FIXED_AMOUNT"132 },133 "billingAddress": {134 "address1": "123 Amoebobacterieae St",135 "address2": "",136 "city": "Ottawa",137 "company": "",138 "countryCode": "CA",139 "firstName": "Bob",140 "lastName": "Bobsen",141 "phone": "",142 "provinceCode": "ON",143 "zip": "K2P0V6"144 },145 "customerId": "gid://shopify/Customer/544365967",146 "lineItems": [147 {148 "appliedDiscount": {149 "description": "Promo",150 "value": 5,151 "valueType": "FIXED_AMOUNT"152 },153 "customAttributes": [],154 "originalUnitPrice": 10,155 "quantity": 1,156 "requiresShipping": true,157 "sku": "draft-151",158 "taxable": true,159 "title": "151cm",160 "variantId": "gid://shopify/ProductVariant/43729076",161 "weight": {162 "unit": "KILOGRAMS",163 "value": 1164 }165 },166 {167 "appliedDiscount": null,168 "customAttributes": [],169 "originalUnitPrice": "10.0",170 "quantity": 2,171 "requiresShipping": true,172 "sku": null,173 "taxable": true,174 "title": "Spring Promo Item",175 "variantId": null,176 "weight": {177 "unit": "KILOGRAMS",178 "value": 1.2179 }180 }181 ],182 "presentmentCurrencyCode": "CAD",183 "shippingAddress": {184 "address1": "",185 "address2": "",186 "city": "",187 "company": "",188 "countryCode": "CA",189 "firstName": "Bob",190 "lastName": "Smith",191 "phone": "",192 "provinceCode": "AB",193 "zip": ""194 },195 "shippingLine": {196 "price": "0.0",197 "title": "Free shipping"198 },199 "taxExempt": false200 }201 },202 },203);204205const data = await response.json();206
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
JSON1{2 "input": {3 "appliedDiscount": {4 "description": "Loyalty",5 "value": 5,6 "valueType": "FIXED_AMOUNT"7 },8 "billingAddress": {9 "address1": "123 Amoebobacterieae St",10 "address2": "",11 "city": "Ottawa",12 "company": "",13 "countryCode": "CA",14 "firstName": "Bob",15 "lastName": "Bobsen",16 "phone": "",17 "provinceCode": "ON",18 "zip": "K2P0V6"19 },20 "customerId": "gid://shopify/Customer/544365967",21 "lineItems": [22 {23 "appliedDiscount": {24 "description": "Promo",25 "value": 5,26 "valueType": "FIXED_AMOUNT"27 },28 "customAttributes": [],29 "originalUnitPrice": 10,30 "quantity": 1,31 "requiresShipping": true,32 "sku": "draft-151",33 "taxable": true,34 "title": "151cm",35 "variantId": "gid://shopify/ProductVariant/43729076",36 "weight": {37 "unit": "KILOGRAMS",38 "value": 139 }40 },41 {42 "appliedDiscount": null,43 "customAttributes": [],44 "originalUnitPrice": "10.0",45 "quantity": 2,46 "requiresShipping": true,47 "sku": null,48 "taxable": true,49 "title": "Spring Promo Item",50 "variantId": null,51 "weight": {52 "unit": "KILOGRAMS",53 "value": 1.254 }55 }56 ],57 "presentmentCurrencyCode": "CAD",58 "shippingAddress": {59 "address1": "",60 "address2": "",61 "city": "",62 "company": "",63 "countryCode": "CA",64 "firstName": "Bob",65 "lastName": "Smith",66 "phone": "",67 "provinceCode": "AB",68 "zip": ""69 },70 "shippingLine": {71 "price": "0.0",72 "title": "Free shipping"73 },74 "taxExempt": false75 }76}
Response
JSON1{2 "draftOrderCalculate": {3 "calculatedDraftOrder": {4 "customer": {5 "id": "gid://shopify/Customer/544365967",6 "email": "bob@example.com",7 "firstName": "Bob",8 "numberOfOrders": "25",9 "defaultAddress": {10 "id": "gid://shopify/MailingAddress/544365967?model_name=CustomerAddress",11 "firstName": "Bob",12 "lastName": "Bobsen",13 "address1": "123 Amoebobacterieae St",14 "address2": "",15 "city": "Ottawa",16 "provinceCode": "ON",17 "zip": "K2P0V6",18 "countryCodeV2": "CA"19 },20 "taxExempt": false21 },22 "billingAddressMatchesShippingAddress": false,23 "totalPriceSet": {24 "presentmentMoney": {25 "amount": "28.05",26 "currencyCode": "CAD"27 },28 "shopMoney": {29 "amount": "22.44",30 "currencyCode": "USD"31 }32 },33 "lineItems": [34 {35 "appliedDiscount": {36 "amountSet": {37 "presentmentMoney": {38 "amount": "6.38",39 "currencyCode": "CAD"40 },41 "shopMoney": {42 "amount": "5.1",43 "currencyCode": "USD"44 }45 },46 "value": 5,47 "valueType": "FIXED_AMOUNT",48 "description": "Promo"49 },50 "discountedTotalSet": {51 "presentmentMoney": {52 "amount": "6.61",53 "currencyCode": "CAD"54 },55 "shopMoney": {56 "amount": "5.29",57 "currencyCode": "USD"58 }59 },60 "product": {61 "id": "gid://shopify/Product/108828309",62 "title": "Draft"63 },64 "quantity": 1,65 "requiresShipping": true,66 "sku": "draft-151",67 "taxable": true,68 "title": "Draft",69 "variantTitle": "151cm",70 "variant": {71 "id": "gid://shopify/ProductVariant/43729076"72 },73 "weight": {74 "value": 1,75 "unit": "KILOGRAMS"76 }77 },78 {79 "appliedDiscount": null,80 "discountedTotalSet": {81 "presentmentMoney": {82 "amount": "25.98",83 "currencyCode": "CAD"84 },85 "shopMoney": {86 "amount": "20.78",87 "currencyCode": "USD"88 }89 },90 "product": null,91 "quantity": 2,92 "requiresShipping": true,93 "sku": null,94 "taxable": true,95 "title": "Spring Promo Item",96 "variantTitle": null,97 "variant": null,98 "weight": {99 "value": 1.2,100 "unit": "KILOGRAMS"101 }102 }103 ],104 "totalTaxSet": {105 "presentmentMoney": {106 "amount": "1.84",107 "currencyCode": "CAD"108 },109 "shopMoney": {110 "amount": "1.47",111 "currencyCode": "USD"112 }113 },114 "totalDiscountsSet": {115 "presentmentMoney": {116 "amount": "12.76",117 "currencyCode": "CAD"118 },119 "shopMoney": {120 "amount": "10.21",121 "currencyCode": "USD"122 }123 },124 "shippingLine": {125 "id": null,126 "custom": true,127 "shippingRateHandle": null,128 "title": "Free shipping",129 "originalPriceSet": {130 "presentmentMoney": {131 "amount": "0.0",132 "currencyCode": "CAD"133 },134 "shopMoney": {135 "amount": "0.0",136 "currencyCode": "USD"137 }138 }139 },140 "presentmentCurrencyCode": "CAD"141 },142 "userErrors": []143 }144}