You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过单次Shopify API调用获取多个集合的产品数据?

Hey there! Let me clarify this for you based on the Shopify Admin API docs you're referencing:

Can I fetch products from multiple collections in a single Shopify API call?

Short answer: No, the 2020-10 version of Shopify's Admin REST API does NOT support retrieving products from multiple collections in one single request. The endpoint you're using (/admin/api/2020-10/collections/{collection_id}/products.json) is designed to only return products for a single specified collection ID, which matches the behavior you're seeing.

Workarounds to get products from multiple collections

1. Batch individual REST API requests

You can loop through your list of target collection IDs and make separate requests for each one. Just keep these points in mind:

  • Respect Shopify's rate limits (for 2020-10, that's 40 requests per minute) to avoid getting throttled.
  • Use async/await or a request library with concurrency control to handle multiple requests efficiently without hitting limits.

Here's a quick example in JavaScript:

const targetCollectionIds = [12345, 67890, 11223];
const shopDomain = "your-store.myshopify.com";
const apiToken = "your-admin-api-token";

// Function to fetch products for a single collection
const fetchProductsForCollection = async (collectionId) => {
  const response = await fetch(
    `https://${shopDomain}/admin/api/2020-10/collections/${collectionId}/products.json`,
    {
      headers: { "X-Shopify-Access-Token": apiToken },
    }
  );
  return response.json();
};

// Fetch all collections' products (with parallel requests)
const allCollectionProducts = await Promise.all(
  targetCollectionIds.map((id) => fetchProductsForCollection(id))
);

Don't forget to handle pagination too—if a collection has more than 50 products, you'll need to use the page parameter or follow the Link header to get all results.

2. Use Shopify's GraphQL API (more efficient)

If you can switch API types, the GraphQL API lets you pull products from multiple collections in a single query, which is much cleaner. Here's an example query:

query GetProductsFromMultipleCollections {
  summerCollection: collection(id: "gid://shopify/Collection/12345") {
    products(first: 250) {
      edges {
        node {
          id
          title
          handle
          priceRange {
            minVariantPrice {
              amount
            }
          }
        }
      }
    }
  }
  winterCollection: collection(id: "gid://shopify/Collection/67890") {
    products(first: 250) {
      edges {
        node {
          id
          title
          handle
        }
      }
    }
  }
}

This approach lets you customize exactly which product fields you want to return, and you can include as many collections as needed in one request (within GraphQL query limits).

Just make sure your API credentials have the read_products and read_collections permissions regardless of which API you use.

内容的提问来源于stack exchange,提问作者user14059282

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:39:37