Shopify API post 多个系列中的一种产品

Shopify API post one product in multiple collections

我们在 Shopify 中管理一个市场,我们打了很多电话。我们想提高来电数量,其中一个关键点是我们在集合中引入产品的时间。一个产品可以插入多个集合中,我们为每个 post/collection:

public function pushCollection($shopifyProductId, $collectionId)
    {
        $collectData = [
            "product_id" => $shopifyProductId,
            "collection_id" => $collectionId
        ];
        $this->client->Collect()->post($collectData);

        return;
    }

问题是,有什么方法可以通过一次调用 post 多个集合中的 1 个产品吗?

非常感谢

你不能那样做。但是,如果您可以累积产品以添加到集合中,则可以在一次调用中将多个产品添加到集合中。

https://help.shopify.com/api/reference/customcollection#update

我来晚了回答,但您可以使用 Shopify 的 GraphQL API 在单个 API 调用中将一个产品添加到多个集合中。这是它的文档:https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/productcreate

将现有产品添加到现有多个集合的 GraphQL API 调用看起来像这样:

mutation {
          productUpdate( input:
            {
            $id:"gid://shopify/Product/{shopifyProductId}"
    collectionsToJoin:["gid://shopify/Collection/{collectionId1}","gid://shopify/Collection/{collectionId2}" ]
            })
            {
                product{
                    id
                }
            }
        }