Updating Shipping in Draft Order using GraphQL draftOrderUpdate mutation not working properly

jkcs
New Member
1 0 0

I am using the draftOrderUpdate mutation to make changes to a Draft Order (like adding or removing a product), and as part of updating the Draft Order, I am running the draftOrderCalculate mutation to get the updated Shipping info prior to adding it into my updated Draft Order object for the draftOrderUpdate mutation.

I have two problems:

1. Even though I am getting the shippingLine object from calculateDraftOrder (https://shopify.dev/docs/admin-api/graphql/reference/orders/shippinglineinput) and passing the same information into the draftOrderUpdate mutation (price, title, and handle), the Shipping field in the Draft Order is always a custom shipping item and not showing as one of the selectable Shipping options in the Draft Order page.

2. When the Draft Order is first created, the Shipping price matches the selectable Shipping option's price on the Draft Order page in Shopify, but if new items are added or if items are deleted from the Draft Order using the draftOrderUpdate mutation, the new Shipping info that I obtained from draftOrderCalculate and passed into the update is not shown in the shippingLine object of the updated draftOrder object (but the items are updated).

I'm unable to figure out what the problem is because the updated Shipping price that shows up is either unchanged, the previous Shipping price, or a price that is neither the old Shipping price nor the correct Shipping price (and I have no idea how this number was calculated).

I tried looking at the draftOrder object itself and there are two fields that show Shipping price - originalPriceSet inside shippingLine and totalShippingPrice. It seems shippingLine is not always updated with the new Shipping information in the draftOrderUpdate mutation, but also the Shipping price that does show up usually doesn't match either originalPriceSet or totalShippingPrice. Is there another field that displays the Shipping price inside the draftOrder object (https://shopify.dev/docs/admin-api/graphql/reference/orders/draftorderupdate#draftorderinput-fields-...)?

I don't get any errors with my draftOrderUpdate mutation and the items are updating so I don't think my input is wrong, but is there something I'm missing with updating the Shipping info? In the draftOrder object, the shippingLine has an ID, but I don't see anywhere to provide this ID in the draftOrderUpdate input.

Here's my draftOrderUpdate mutation:

mutation draftOrderUpdate($id: ID!, $input: DraftOrderInput!) {
                    draftOrderUpdate(id: $id, input: $input) {
                      draftOrder {
                        id
                        name
                      }
                      userErrors {
                        field
                        message
                      }
                    }
                  }

 

Here's the input variable:

{
   "billingAddress": {
      "address1": "123 fake st",
      "city": "shelbyville",
      "company": "Acme Products",
      "countryCode": "PL",
      "phone": "+15555555555",
      "zip": "12345"
   },
   "customAttributes": {
      "key": "SalesforceQuoteId",
      "value": "00000043"
   },
   "email": "test@test.com",
   "lineItems": [
      {
         "variantId": "gid://shopify/ProductVariant/33353411002421",
         "quantity": 1
      },
      {
         "variantId": "gid://shopify/ProductVariant/33353411428405",
         "quantity": 2
      },
      {
         "variantId": "gid://shopify/ProductVariant/33353371615285",
         "quantity": 1
      },
      {
         "appliedDiscount": {
            "value": 10,
            "valueType": "PERCENTAGE"
         },
         "variantId": "gid://shopify/ProductVariant/33353406808117",
         "quantity": 1
      }
   ],
   "shippingAddress": {
      "address1": "123 fake st",
      "city": "shelbyville",
      "company": "Acme Products",
      "countryCode": "PL",
      "phone": "+15555555555",
      "zip": "12345"
   },
   "shippingLine": {
      "price": "731.33",
      "shippingRateHandle": "dhl_express-P-731.33",
      "title": "DHL Express Worldwide"
   },
   "taxExempt": false
}

 

0 Likes
GrahamS
Shopify Staff
Shopify Staff
45 7 2

Hello @jkcs ,

I tried to replicate your circumstances via our own queries, however my results returned successful carrier rates when calculated and applied to an existing draft order, rather than custom:

https://screenshot.click/21-21-wtiwk-9y71a.jpg

I tried this with various permutations of different variant quantities and shipping info, but ultimately always had rates update successfully and not as custom. Can you provide a screenshot of the call body + response fields showing a custom rate? There may be some additional differences between our calls.

 

 

Graham S | API Support @ Shopify
- Was my reply helpful? Click Like to let me 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

0 Likes