Calculate shipping rate with draft order api

Solved
Lilante
New Member
2 0 0

There is also another option. Use this code snippet:

      "shipping_line": {
            "custom":"true",
            "title":"Fedex",
            "price":"12.99"
        }
 
0 Likes
nepthar
Tourist
5 0 2

Can you explain what you mean by that? Are you suggesting we just charge everyone 12.99 for "Fedex"?

0 Likes
gorodezkiy
Shopify Expert
6 0 10

For our regular private app I could get available shipping rates by using GraphQL Admin API - draftOrderCalculate mutation - https://shopify.dev/docs/admin-api/graphql/reference/orders/draftordercalculate#interactive-example-... :

Query POST https://jennyyoo-staging.myshopify.com/admin/api/2020-01/graphql.json :

mutation draftOrderCalculate($input: DraftOrderInput!) {
  draftOrderCalculate(input: $input) {
    calculatedDraftOrder {
      subtotalPrice
      totalPrice
      totalShippingPrice
      totalTax
      availableShippingRates {
          handle
          title
          price {
              amount
          }
      }
    }
    userErrors {
      field
      message
    }
  }
}

 

Input:

{
    "input": {
        "lineItems": [{
            "variantId": "gid://shopify/ProductVariant/123",
            "quantity": 1,
            "appliedDiscount": null
        }],
        "shippingAddress": {
            "firstName": "Eduard",
            "lastName": "...",
            "address1": "...",
            "address2": "...",
            "phone": "123",
            "city": "Miami",
            "countryCode": "US",
            "provinceCode": "FL",
            "zip": "123"
        },
        "billingAddress": {
            "firstName": "Eduard",
            "lastName": "...",
            "address1": "...",
            "address2": "...",
            "phone": "123",
            "city": "Miami",
            "countryCode": "US",
            "provinceCode": "FL",
            "zip": "123"
        },
        "email": "eduard@example.com"
    }
}

 

Response:

{
    "data": {
        "draftOrderCalculate": {
            "calculatedDraftOrder": {
                "subtotalPrice": "285.00",
                "totalPrice": "319.20",
                "totalShippingPrice": "0.00",
                "totalTax": "34.20",
                "availableShippingRates": [
                    {
                        "handle": "shopify-USPS%20First%20Class%20Mail-2.75",
                        "title": "USPS First Class Mail",
                        "price": {
                            "amount": "2.75"
                        }
                    },
                    {
                        "handle": "shopify-Fedex%20Home%20Delivery-9.95",
                        "title": "Fedex Home Delivery",
                        "price": {
                            "amount": "9.95"
                        }
                    },
                    {
                        "handle": "fedex-FEDEX_EXPRESS_SAVER-22.67",
                        "title": "FedEx FedEx Express Saver®",
                        "price": {
                            "amount": "22.67"
                        }
                    },
                    {
                        "handle": "fedex-FEDEX_2_DAY-30.84",
                        "title": "FedEx FedEx 2Day®",
                        "price": {
                            "amount": "30.84"
                        }
                    },
                    {
                        "handle": "fedex-STANDARD_OVERNIGHT-46.24",
                        "title": "FedEx FedEx Standard Overnight®",
                        "price": {
                            "amount": "46.24"
                        }
                    }
                ]
            },
            "userErrors": []
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 11,
            "actualQueryCost": 11,
            "throttleStatus": {
                "maximumAvailable": 2000.0,
                "currentlyAvailable": 1989,
                "restoreRate": 100.0
            }
        }
    }
}

 

ApiPaul
Tourist
4 0 1

Thanks @gorodezkiy you rocks!

 
 
 
Skylitech
Shopify Partner
3 0 3

Hi, 

Do you have any solution to this?

We need this.

There is no way to calculate to fetch available shipping options with draft order API.

 

0 Likes