- Customers
- Customer Address
- Retrieves a list of addresses for a customer
- Creates a new address for a customer
- Retrieves details for a single customer address
- Updates an existing customer address
- Removes an address from a customer’s address list
- Performs bulk operations for multiple customer addresses
- Sets the default address for a customer
- CustomerSavedSearch
- Customer
- Retrieves a list of customers
- Creates a customer
- Searches for customers that match a supplied query
- Retrieves a single customer
- Updates a customer
- Deletes a customer
- Creates an account activation URL for a customer
- Sends an account invite to a customer
- Retrieves a count of customers
- Retrieves all orders that belong to a customer
- Sales channels
- Checkout
- CollectionListing
- Retrieve collection listings that are published to your app
- Retrieve product_ids that are published to a collection_id
- Retrieve a specific collection listing that is published to your app
- Create a collection listing to publish a collection to your app
- Delete a collection listing to unpublish a collection from your app
- Product ResourceFeedback
- MobilePlatformApplication
- ProductListing
- Retrieve product listings that are published to your app
- Retrieve product_ids that are published to your app
- Retrieve a count of products that are published to your app
- Retrieve a specific product listing that is published to your app
- Create a product listing to publish a product to your app
- Delete a product listing to unpublish a product from your app
- ResourceFeedback
- Payment
- Products
- Collect
- Collection
- CustomCollection
- Product
- Product Image
- Product Variant
- SmartCollection
- Orders
- Abandoned checkouts
- DraftOrder
- Order Risk
- Transaction
- Order
- Refund
- Access
- Billing
- Online store
- Asset
- Blog
- Article
- Retrieves a list of all articles from a blog
- Creates an article for a blog
- Retrieves a count of all articles from a blog
- Receive a single Article
- Updates an article
- Deletes an article
- Retrieves a list of all article authors
- Retrieves a list of all article tags
- Retrieves a list of all article tags from a specific blog
- Redirect
- Comment
- ScriptTag
- Page
- Theme
- Shipping and fulfillment
- CancellationRequest
- CarrierService
- AssignedFulfillmentOrder
- FulfillmentEvent
- Fulfillment
- Retrieves fulfillments associated with an order
- Retrieves fulfillments associated with a fulfillment order
- Retrieves a count of fulfillments associated with a specific order
- Receive a single Fulfillment
- Creates a fulfillment for one or many fulfillment orders
- Updates the tracking information for a fulfillment
- Cancels a fulfillment
- FulfillmentOrder
- Retrieves a list of fulfillment orders for a specific order
- Retrieves a specific fulfillment order
- Cancel a fulfillment order
- Marks a fulfillment order as incomplete
- Moves a fulfillment order to a new location
- Marks the fulfillment order as open
- Reschedules the fulfill_at time of a scheduled fulfillment order
- Applies a fulfillment hold on an open fulfillment order
- Sets deadline for fulfillment orders
- Releases the fulfillment hold on a fulfillment order
- LocationsForMove
- FulfillmentRequest
- FulfillmentService
- Shopify Payments
- Analytics
- Deprecated API calls
- Discounts
- DiscountCode
- Creates a discount code
- Retrieves a list of discount codes
- Updates an existing discount code
- Retrieves a single discount code
- Deletes a discount code
- Retrieves the location of a discount code
- Retrieves a count of discount codes for a shop
- Creates a discount code creation job
- Retrieves a discount code creation job
- Retrieves a list of discount codes for a discount code creation job
- PriceRule
- DiscountCode
- Inventory
- Events
- MarketingEvent
- Metafield
- Plus
- Store properties
- TenderTransaction
Create a new DraftOrder
Creates a draft order.
Using the DraftOrder
resource you can create orders in draft state using product variant line items,
or custom line items. To create a product variant draft order, provide the variant_id
, quantity
and discount
properties. To create a custom line item, provide the title
, price
, taxable
,
and quantity
properties.
Note
If you are using this endpoint with a Partner development store or a trial store, then you can only create five draft orders per minute.
Polling
When you create and update draft orders some calculations are done asynchronously, such as calculating shipping and taxes. There might be times when a draft order is created but these calculations haven't completed. In these cases, you need to poll the draft order until the calculations are finished.When a draft order requires polling, a 202 accepted
response code is returned along with location
and retry-after
response headers. The location
header refers to the URL to be polled, and retry-after
denotes the interval (in seconds) at which polling requests should be sent. When the draft order is ready, a 200 OK
response code will be returned.
About custom shipping lines
You can use the DraftOrder resource to send orders with custom shipping lines. A custom shipping line includes atitle
and price
with handle
set to Nil
. A shipping line with a carrier provided shipping rate
(currently set via the Shopify admin) includes the shipping rate handle.
Applying discounts
A draft order and its line items can have one discount each. Calculations for discounts are based on the setting
of the value_type
property, which can be set to either fixed_amount
or percentage
.
For example, you can apply a fixed amount discount to a draft order to reduce the price by the specified value
property.
When you use a percentage discount, the discount amount
property is the price multiplied by the value
property.
For line item discounts, the value
property is applied per individual unit of the item, based on the line item's quantity.
Calculating line item discount amounts
For fixed_amount
discounts, the total amount
corresponds to the line item quantity
times the value of the discount.
For percentage discounts, the total amount
corresponds to the following:
amount = floor(price * quantity * value) / 100
, where floor()
is the usual round down function.
For non-fractional currencies, this formula needs to use round()
instead of floor()
, and the division by 100 takes place inside the rounding, resulting in a non-fractional value.
Otherwise, an error is returned.
amount = round(price * quantity * value / 100)
Line item examples
Fixed amount discount
For a $19.99 line item with quantity of 2 and with $5 dollars off, discount amount corresponds to $10 ($5 * 2):
applied_discount: { "value_type": "fixed_amount", "value": 5, "amount": 10 }
Percentage discount
For a $19.99 line item with quantity of 2 and with 15% off, discount amount corresponds to $5.99 (floor ($19.99 * 2 * 15) / 100):
applied_discount: { "value_type": "percentage", "value": 15, "amount": 5.99 }
Loading and removing customers
You can load a customer to a draft order by sending the customer_id
as part of the draft order resource.
We recommend removing a customer from a draft order by making a POST request with the Customer
resource set to null
,
without specifying an email, shipping address, or billing address.
A customer can also be removed by setting customer
, email
, shipping_address
, and billing_address
to null
.
请求参数
resource to load customer shipping information. Valid values: true or false.
示例代码
curl --location --request POST 'https://demo.myshopify.com//admin/api//draft_orders.json'
返回响应
and removing customers. For more information about the
customer
resource, seethe Customer documentation.
shipping_address
is optional and will not be available on orders that don't require shipping. The shipping_address
resource has the following properties:- address1: The street address of the shipping address.
- address2: An optional additional field for the street address of the shipping address.
- city: The city of the shipping address.
- company: The company of the person associated with the shipping address.
- country: The name of the country of the shipping address.
- country_code: The two-letter code for the country of the shipping address.
- first_name: The first name of the person associated with the payment method.
- last_name: The last name of the person associated with the payment method.
- latitude: The latitude of the shipping address.
- longitude: The longitude of the shipping address.
- name: The full name of the person associated with the payment method.
- phone: The phone number at the shipping address.
- province: The name of the state or province of the shipping address.
- province_code: The two-letter abbreviation of the state or province of the shipping address.
- zip: The zip or postal code of the shipping address.
billing_address
resource has the following properties:- address1: The street address of the billing address.
- address2: An optional additional field for the street address of the billing address.
- city: The city of the billing address.
- company: The company of the person associated with the billing address.
- country: The name of the country of the billing address.
- country_code: The two-letter code (ISO 3166-1 alpha-2 two-letter country code) for the country of the billing address.
- first_name: The first name of the person associated with the payment method.
- last_name: The last name of the person associated with the payment method.
- latitude: The latitude of the billing address.
- longitude: The longitude of the billing address.
- name: The full name of the person associated with the payment method.
- phone: The phone number at the billing address.
- province: The name of the billing address region, such as province, state, or prefecture.
- province_code: The two-letter abbreviation of the region for the billing address.
- zip: The postal code of the billing address, such as zip, postcode, or Eircode.
name
and value
keys.Each draft order must include at least one
line_item
.Each
line_item
resource has the following properties:- custom: Read only field Whether this is a custom line item or a product variant line item.
If set totrue
indicates a custom line item.
If set tofalse
indicates a product variant line item. - id: The ID of the line item.
- variant_id: The ID of the product variant corresponding to the line item. Required for a product variant line item. Set to
null
for a custom line item. - product_id: The ID of the product corresponding to the line item’s product variant.
- name: The name of the product.
- variant_title: The title of the product variant. Defaults to
Custom
for custom line items created via the API. - vendor: The vendor.
- quantity: The number of products that were purchased.
- gift_card: Indicates if the product is a gift card. Valid values:
true
orfalse
. - fulfillment_service: The service provider responsible for fulfillment. Valid values are either
manual
or the name of the provider, for example amazon, shipwire. Defaults tomanual
for custom line items. - properties: An array of custom information for an item that has been added to the draft order,
often used to provide product customization options.
Copied to created order when draft order is completed. - applied_discount: The discount applied to the line item. For more information, see the
applied_discount
property. - tax_lines: Read only field The calculated rate and amount of taxes for the line item.
- price: The amount of tax to be charged.
- rate: The rate of tax to be applied.
- title: The name of the tax.
- title: The title of the product or variant. Applicable only to custom line items. Required field.
- price: The price of the item before discounts have been applied. Applicable only to custom line items. Required field.
- grams: The weight of the item in grams. Applicable only to custom line items. If not specified, defaults to 0.
- requires_shipping: Whether the fulfillment requires shipping. Applicable only to custom line items. Valid values:
true
orfalse.
- sku: A unique identifier for the item in the fulfillment. Applicable only to custom line items.
- taxable: Whether the product is taxable. Applicable only to custom line items.
- amount: The amount that is owed according to the payment terms.
- currency: The presentment currency for the payment.
- payment_terms_name: The name of the selected payment terms template for the draft order.
- payment_terms_type: The type of selected payment terms template for the draft order.
- due_in_days: The number of days between the invoice date and due date that is defined in the selected payment terms template.
- payment_schedules: An array of schedules associated to the payment terms.
- amount: The amount that is owed according to the payment terms.
- currency: The presentment currency for the payment.
- issued_at: The date and time when the payment terms were initiated.
- due_at: The date and time when the payment is due. Calculated based on
issued_at
anddue_in_days
or a customized fixed date if the type is fixed. - completed_at: The date and time when the purchase is completed. Returns null initially and updates when the payment is captured.
- expected_payment_method: The name of the payment method gateway.
shipping_line
resource has the following properties:- custom: Whether this is a regular shipping line or custom shipping line.
- handle: The handle of the shipping rate which was selected and applied. Required for regular shipping lines.
- title: The title of the shipping method. Required for custom shipping lines. (maximum: 255 characters)
- price: The price of the shipping method. Required for custom shipping lines.
You can register the channels that your app is managing by completing the Order Attribution Access Form.
After you've submited the form, you'll need to wait for your request to be processed by Shopify. You can find a list of your channels in the Partner Dashboard, in your app's Marketplace extension.
You can specify a handle as the
source_name
value in your request.Each individual tag is limited to 40 characters in length. For example,
tags: "tag1","tag2","tag3"
.false
,then Shopify refers to the
taxable
field for each line_item
.If a customer is applied to the draft order, then Shopify uses the customer's
tax_exempt
field instead.tax_lines
resource has the following properties:- price: The amount of tax to be charged.
- rate: The rate of tax to be applied.
- title: The name of the tax.
applied_discount
resource and each draft order line item can have its own applied_discount
.The
applied_discount
resource has the following properties:- title: Title of the discount.
- description: Reason for the discount.
- value: The value of the discount. If the type of discount is
fixed_amount
, then it corresponds to a fixed dollar amount. If the type ispercentage
, then it corresponds to percentage. - value_type: The type of discount. Valid values:
percentage
,fixed_amount
. - amount: The applied amount of the discount, based on the setting of
value_type
. For more information, see Applying discounts.
Valid values:
true
or false
.including taxes and discounts.
The status of a draft order as it transitions into an order. When a draft order is created it is set to open
status.
The invoice can then be sent to the customer, and status
changes to invoice_sent
.
The draft order can then be paid, set to pending, or paid by credit card. In each case, the draft order is set to completed
and an order is created.
After a draft order is set to completed
the only further modifications that can be made are adding tags or metafields.
Valid values:
{
"draft_order": {
"id": 1069920479,
"note": null,
"email": "bob.norman@mail.example.com",
"taxes_included": false,
"currency": "USD",
"invoice_sent_at": null,
"created_at": "2023-01-03T12:58:43-05:00",
"updated_at": "2023-01-03T12:58:43-05:00",
"tax_exempt": false,
"completed_at": null,
"name": "#D5",
"status": "open",
"line_items": [
{
"id": 1066630384,
"variant_id": null,
"product_id": null,
"title": "Custom Tee",
"variant_title": null,
"sku": null,
"vendor": null,
"quantity": 2,
"requires_shipping": false,
"taxable": true,
"gift_card": false,
"fulfillment_service": "manual",
"grams": 0,
"tax_lines": [],
"applied_discount": null,
"name": "Custom Tee",
"properties": [],
"custom": true,
"price": "20.00",
"admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1066630384"
}
],
"shipping_address": {
"first_name": null,
"address1": "Chestnut Street 92",
"phone": "555-625-1199",
"city": "Louisville",
"zip": "40202",
"province": "Kentucky",
"country": "United States",
"last_name": null,
"address2": "",
"company": null,
"latitude": null,
"longitude": null,
"name": "",
"country_code": "US",
"province_code": "KY"
},
"billing_address": {
"first_name": null,
"address1": "Chestnut Street 92",
"phone": "555-625-1199",
"city": "Louisville",
"zip": "40202",
"province": "Kentucky",
"country": "United States",
"last_name": null,
"address2": "",
"company": null,
"latitude": null,
"longitude": null,
"name": "",
"country_code": "US",
"province_code": "KY"
},
"invoice_url": "https://jsmith.myshopify.com/548380009/invoices/b21e68f2f1e19263509b19a8286d2d09",
"applied_discount": {
"description": "Custom discount",
"value": "10.0",
"title": "Custom",
"amount": "10.00",
"value_type": "fixed_amount"
},
"order_id": null,
"shipping_line": null,
"tax_lines": [],
"tags": "",
"note_attributes": [],
"total_price": "30.00",
"subtotal_price": "30.00",
"total_tax": "0.00",
"presentment_currency": "USD",
"total_line_items_price_set": {
"shop_money": {
"amount": "40.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "40.00",
"currency_code": "USD"
}
},
"total_price_set": {
"shop_money": {
"amount": "30.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "30.00",
"currency_code": "USD"
}
},
"subtotal_price_set": {
"shop_money": {
"amount": "30.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "30.00",
"currency_code": "USD"
}
},
"total_tax_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"total_discounts_set": {
"shop_money": {
"amount": "10.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "10.00",
"currency_code": "USD"
}
},
"total_shipping_price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"payment_terms": null,
"admin_graphql_api_id": "gid://shopify/DraftOrder/1069920479",
"customer": {
"id": 207119551,
"email": "bob.norman@mail.example.com",
"accepts_marketing": false,
"created_at": "2023-01-03T12:56:35-05:00",
"updated_at": "2023-01-03T12:56:35-05:00",
"first_name": "Bob",
"last_name": "Norman",
"orders_count": 1,
"state": "disabled",
"total_spent": "199.65",
"last_order_id": 450789469,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"tags": "",
"last_order_name": "#1001",
"currency": "USD",
"phone": "+16136120707",
"accepts_marketing_updated_at": "2005-06-12T11:57:11-04:00",
"marketing_opt_in_level": null,
"tax_exemptions": [],
"email_marketing_consent": {
"state": "not_subscribed",
"opt_in_level": null,
"consent_updated_at": "2004-06-13T11:57:11-04:00"
},
"sms_marketing_consent": {
"state": "not_subscribed",
"opt_in_level": "single_opt_in",
"consent_updated_at": "2023-01-03T12:56:35-05:00",
"consent_collected_from": "OTHER"
},
"admin_graphql_api_id": "gid://shopify/Customer/207119551",
"default_address": {
"id": 207119551,
"customer_id": 207119551,
"first_name": null,
"last_name": null,
"company": null,
"address1": "Chestnut Street 92",
"address2": "",
"city": "Louisville",
"province": "Kentucky",
"country": "United States",
"zip": "40202",
"phone": "555-625-1199",
"name": "",
"province_code": "KY",
"country_code": "US",
"country_name": "United States",
"default": true
}
}
}
}