简体   繁体   中英

Shopify API post one product in multiple collections

we're managing a marketplace in Shopify, and we're doing a lot of calls. We'd like to improve the number of calls and one of the keypoints is when we introduce the product in collections. One product can be inserted in multiple collections, and we do this for each post/collection:

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

        return;
    }

The question is, is there any way to post 1 product in multiple collections with a single call?

Thank you so much

You cannot do that. But if you can accumulate products to add to collections you can add multiple products to a collection in a single call.

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

I am a little late to answer but you can add one product to multiple collections in a single API call using Shopify's GraphQL API. Here's the documentation on it: https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/productcreate

The GraphQL API call to add an already existing product to already existing multiple collections would look something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM