Update Shipping Address on an existing order -- the New Way!!! (SOLVED)

As of api version 2024-07, it’s someone easier to change the shipping address and have sales tax calculated properly. There is no need to have a ShippingAdjustment line item any more.

  1. Change the shipping address on Shopify:
mutation orderUpdate($input: OrderInput!) {orderUpdate(input: $input) {order { email customer {id} } userErrors {field message}}}
    {"input": {"id": "gid://shopify/Order/12345","shippingAddress":{"address1":"1234 Main Street","city":"Anytown","company":"","provinceCode":"CA","zip":"12345","countryCode":"US","firstName":"John","lastName":"Smith","phone":"+15555551234"}}}

Edit the order:

mutation {orderEditBegin(id: "gid://shopify/Order/1234") {calculatedOrder{id totalOutstandingSet{shopMoney{amount currencyCode}} shippingLines {id price {presentmentMoney {amount currencyCode} shopMoney {amount currencyCode} } title } lineItems(first:140){nodes{id quantity variant{id idProduct:metafield(key:""kp_idproduct"",namespace:""products""){value}} title sku discountedUnitPriceSet{presentmentMoney{amount}}editableQuantity variantTitle  originalUnitPriceSet{presentmentMoney{amount}}calculatedDiscountAllocations{ discountApplication{allocationMethod, id, appliedTo}}}}} userErrors {field message}}}

Remove and re-add the line items. This calculates the new sales tax, if applicable
For Each lineItem in lineItems:

mutation orderEditSetQuantity{orderEditSetQuantity(id:  "<calculatedOrder.id>" , lineItemId: "<lineItem.id>", quantity:0) {userErrors {field message}}}
mutation orderEditSetQuantity{orderEditSetQuantity(id:  "<calculatedOrder.id>" , lineItemId: "<lineItem.id>", quantity:<lineItem.quantity>) {userErrors {field message}}}

You’ll also need to add any discounts to the line item at this point:
percentage:

mutation { orderEditAddLineItemDiscount(id: "<calculatedOrder.id>", lineItemId: "<lineItem.id>", discount: { percentValue: "<discountPercentage>",description:"<discountName>"}){ addedDiscountStagedChange { id } calculatedLineItem { id } calculatedOrder { id } userErrors { field message } } }
fixed_amount:
mutation { orderEditAddLineItemDiscount(id: "<calculatedOrder.id>", lineItemId: "<lineItem.id>", discount: {fixedValue: {currencyCode: USD, amount: "<fixedAmount>"},description:"<discountName>"}){ addedDiscountStagedChange { id } calculatedLineItem { id } calculatedOrder { id } userErrors { field message } } }

Remove the current shipping lines:
For each shippingLine in shippingLines:

mutation {orderEditRemoveShippingLine(id: "<calculatedOrder.id>", shippingLineId: "<shippingLine.id>") {calculatedOrder {id shippingLines {id stagedStatus}} userErrors {field message code}}}

Add the new shipping line:

mutation {orderEditAddShippingLine(id: "<calculatedOrder.id>", shippingLine: { title: "<shippingLineTitle>", price: { amount: <shippingAmount>, currencyCode: USD }}) {calculatedOrder { id shippingLines {id stagedStatus title price {shopMoney {currencyCode amount}}}} userErrors {field message code}}}

Save the order:

mutation commitEdit{orderEditCommit(id:"<calculatedOrder.id>",notifyCustomer:true,staffNote:"<myComment>"){order{id totalOutstandingSet{shopMoney{amount currencyCode}} totalReceivedSet{shopMoney{amount currencyCode}} netPaymentSet{shopMoney{amount currencyCode}} lineItems(first:240){nodes{id quantity fulfillableQuantity title variant{id}}}} userErrors{field message}}}