Re: draftOrderCreate - ShippingLineInput not working

draftOrderCreate - ShippingLineInput not working

jake-frate
Shopify Partner
13 1 4

Hi,

 

I am trying to use the draftOrderCreate GraphQL API to create a zero cost order (i.e., zero subtotal, zero taxes, and zero shipping). But, despite my effort to set the shippingLine input to $0, the draft orders are getting created with default positive shipping costs.

 

Here is the DraftOrderInput I passed to the API:
{'billingAddress': {'address1': '1 Ted Rogers Way', 'address2': None, 'city': 'Toronto', 'company': None, 'country': 'Canada', 'countryCode': 'CA', 'firstName': None, 'id': None, 'lastName': None, 'phone': '256-316-0966', 'province': 'Ontario', 'provinceCode': 'ON', 'zip': 'M4Y 3B7'}, 'email': '[email protected]', 'lineItems': [{'quantity': 1, 'variantId': 'gid://shopify/ProductVariant/45357904986401'}], 'note': 'Exchange for Order #1063', 'phone': '256-316-0966', 'presentmentCurrencyCode': 'CAD', 'purchasingEntity': {'customerId': 'gid://shopify/Customer/7139793731873'}, 'reserveInventoryUntil': '2023-10-11T12:49:27.835601-04:00', 'shippingAddress': {'address1': '1 Ted Rogers Way', 'address2': None, 'city': 'Toronto', 'company': None, 'country': 'Canada', 'countryCode': 'CA', 'firstName': None, 'id': None, 'lastName': None, 'phone': '256-316-0966', 'province': 'Ontario', 'provinceCode': 'ON', 'zip': 'M4Y 3B7'}, 'shippingLine': {'price': '0.0', 'shippingRateHandle': 'free-shipping', 'title': 'Free Shipping'}, 'tags': [''], 'useCustomerDefaultAddress': True, 'visibleToCustomer': True, 'appliedDiscount': {'description': 'Items in an exchange order are not charged.', 'title': 'Zero-cost order', 'value': 100.0, 'valueType': 'PERCENTAGE'}}

 

And here's the response (notice the shippingLine as 'International Shipping' with $42):

{'data': {'draftOrderCreate': {'draftOrder': {'id': 'gid://shopify/DraftOrder/1129791127841', 'name': '#D126', 'shippingLine': {'code': 'International Shipping', 'custom': False, 'deliveryCategory': 'shipping', 'originalPriceSet': {'presentmentMoney': {'amount': '42.0', 'currencyCode': 'CAD'}}, 'shippingRateHandle': '5a141a6edf7ffccc57390a16d58bf042', 'source': 'shopify', 'title': 'International Shipping'}}, 'userErrors': []}}, 'extensions': {'cost': {'requestedQueryCost': 12, 'actualQueryCost': 12, 'throttleStatus': {'maximumAvailable': 1000.0, 'currentlyAvailable': 988, 'restoreRate': 50.0}}}}

 

Thanks,
Frate Team

Replies 2 (2)

jake-frate
Shopify Partner
13 1 4

I think I just solved my problem: by removing shippingRateHandle from the shipping line input, and only providing the price (as a float) and title (as a string).

 

This is a weird bug that shopify could perhaps fix, no?

ShopifyDevSup
Shopify Staff
1453 238 511

Hey @jake-frate! Thanks for sharing that and that you've found a resolution. 

 

The behaviour you're seeing is expected. When you include the shippingRateHandle, this will provide the shipping rate from your shipping settings, and when it's excluded it will use the price and title for a custom rate. 

Our REST documentation explains this behaviour a bit better: 

About custom shipping lines

You can use the DraftOrder resource to send orders with custom shipping lines. A custom shipping line includes a title 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.

I have passed on feedback to our documentation team to make our documentation more clear on what to expect for these fields. 

 

Hope that helps! 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog