How to retrieve all delivery profile items - DeliveryProfileItem node has no "id" field

Sorry for the late reply. I did find a temporary work-around.

First I get the shipping zones using the REST API.

const res = await fetch(`https://${shop}/admin/api/${SHOPIFY_API_VERSION}/shipping_zones.json`, {
  method: 'GET',
  headers: { 'X-Shopify-Access-Token': accessToken },
});

const { shipping_zones } = await res.json();

Then I retrieve the delivery profile id from each zone (except the first one which is the default zone, not a custom one, but can’t really recall why I’m skipping it in my case).

const customDeliveryProfileIds = Array.from(new Set(shipping_zones.map(zone => zone.profile_id))).slice(1);

Then I pass those profile ids into a GraphQL query.

const { data } = await apolloClient.query({
  query: gql`
    query deliveryProfiles($profileIds: [ID!]!) {
      nodes(ids: $profileIds) {
        ... on DeliveryProfile {
          id
          profileItems(first: 250) {
            edges {
              node {
                product {
                  id
                }
              }
            }
          }
        }
      }
    }
  `,
  variables: { profileIds: customDeliveryProfileIds },
});

I guess the trick is to use the nodes query with a specific list of ids (the number of ids you query doesn’t actually increase the query cost). However there’s still the limitation that it only gets the first 250 products of each delivery profile :confused:

It’s ok for now but I’m waiting for a resolution of this so I can do the bulk query.

1 Like