Edits history of script submission #23746 for ' List Locations (shopify)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Locations
     * List the store's inventory locations (warehouses, retail stores, fulfillment apps). Filter with Shopify's search syntax (e.g. `name:Warehouse`, `active:true`). Returns one page; pass pageInfo.endCursor as after for the next.
     */
    export async function main(
      auth: RT.Shopify,
      query: string | undefined,
      include_inactive: boolean | undefined,
      first: number | undefined,
      after: string | undefined
    ) {
      const response = await fetch(
        `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
        {
          method: "POST",
          headers: {
            "X-Shopify-Access-Token": auth.token,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({
            query: `query ($first: Int!, $after: String, $query: String, $includeInactive: Boolean) { locations(first: $first, after: $after, query: $query, includeInactive: $includeInactive) { nodes { id legacyResourceId name isActive fulfillsOnlineOrders shipsInventory hasActiveInventory createdAt updatedAt address { address1 address2 city province provinceCode zip country countryCode phone formatted } } pageInfo { hasNextPage endCursor } } }`,
            variables: {
              first: first || 50,
              after: after || undefined,
              query: query || undefined,
              includeInactive: include_inactive || undefined,
            },
          }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      const { data, errors } = await response.json()
      if (errors) {
        throw new Error(JSON.stringify(errors))
      }
    
      return data.locations
    }
    

    Submitted by hugo989 3 hours ago