Admin API: retrieve list of available shipping methods.

Admin API: retrieve list of available shipping methods.

mtrxn
Shopify Partner
1 0 0

Is there a way I can get a list of currently available shipping methods so I can display them to the customer inside a 3rd party app? Very similar to what checkout does.
image.png
I was only able to get a names and prices so far. I'm using

GET /admin/api/2022-04/shipping_zones.json

endpoint.
image.png

I'd love to know is there a way I can also get a shipping time information using Admin API?  And what's the purpose of id property? Can I use it during Order creation (also using Admin API)?

Replies 4 (4)

dotamir
Shopify Partner
4 0 0

Hi. How did it go? Could you find a way?
I'm facing same issue

 

samirNonDormire
Visitor
1 0 1

QUERY;

query {
  deliveryProfiles(first10) {
    edges {
        node {
            profileLocationGroups {
                locationGroupZones(first5) {
                    edges {
                        node {
                            methodDefinitions(first5) {
                                edges {
                                    node {
                                        id
                                        name
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  }
}
RESPONSE:
{
    "data": {
        "deliveryProfiles": {
            "edges": [
                {
                    "node": {
                        "profileLocationGroups": [
                            {
                                "locationGroupZones": {
                                    "edges": [
                                        {
                                            "node": {
                                                "methodDefinitions": {
                                                    "edges": [
                                                        {
                                                            "node": {
                                                                "id""gid://shopify/DeliveryMethodDefinition/778642817312",
                                                                "name""Standard"
                                                            }
                                                        },
                                                        {
                                                            "node": {
                                                                "id""gid://shopify/DeliveryMethodDefinition/778642850080",
                                                                "name""Express"
                                                            }
                                                        }
                                                    ]
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost"442,
            "actualQueryCost"11,
            "throttleStatus": {
                "maximumAvailable"1000.0,
                "currentlyAvailable"989,
                "restoreRate"50.0
            }
        }
    }
}
VladSofronov
Shopify Partner
6 1 3

Hi! A question. I'm trying to build a shipping discount app using Shopify functions and shipping discount API. When I query cart graphQL API for delivery methods, I get this response:

{
        "id": "gid://shopify/CartDeliveryGroup/0",        "deliveryOptions": [          {
            "handle": "16c3896838b1c095431f263d073856c9-73a2bf35e295daaa5f6254f4ae9788b8",            "title": "Standard"
          },
          {
            "handle": "16c3896838b1c095431f263d073856c9-aea3f94d72fdf702e20871d1b8918f56",            "title": "Express"
          }
        ],
        "selectedDeliveryOption": {          "handle": "16c3896838b1c095431f263d073856c9-73a2bf35e295daaa5f6254f4ae9788b8",          "title": "Standard"
        }
      }

To apply the discount I use targets.deliveryOptions.handle . But how I can get this deliveryOption handle from the admin API( to surface the available options for user in the UI)?

 

When I'm executing your query I only get id and name, no handle.

Ahsan-ah-med
Shopify Partner
27 3 3

You can show the names of your shipping methods by using the query above and then pass the names to the function and filter out the handles with the same name.
Like This code:

const selectedShippingOption =
    input?.cart?.deliveryGroups[0]?.selectedDeliveryOption;

  const getPayMethod = input?.paymentMethods.find((method) => method?.name.toLocaleLowerCase().includes("cash on delivery"));

  if (selectedShippingOption?.title?.toLocaleLowerCase().includes("express")) {
    return {
      operations: [
        {
          hide: {
            paymentMethodId: getPayMethod?.id || '',
          }
        }
      ]
    }
  }
Ahsan Ahmed
Shopify Developer | 2 Years of Experience
Shopify App Developer | 1 Year Experience
I'm Build Custom App for Client Requirements Using Shopify Functions, Shopify Checkout Ui Extensions, Remix App,
Transforming Websites into Shopify
 Converting Existing Websites (WooCommerce, Figma, Magento, etc.) to Shopify
️ Developing Custom Shopify Apps for Unique Client Needs
 Enhancing Shopify Functions with Checkout Extensions for Plus Users
Let's Build Your Dream Store Together!