skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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
                    }
                }
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search