Prakash Patel
Prakash Patel

Reputation: 125

Create product with assign collection in shopify

I have tried to create product in myshopify with help of below parameter.Product is creating in myshopify admin but the collection is not assign so kindly let met know how can I assign collection with this.

 "product"=> array(
                "title"=> $product->getName(),
                "body_html"=> $product->getDescription(),
                "vendor"=> "Troupe",
                "product_type"=>"",
                "collection_ids" => array('31231','231312'),
                "published"=> true ,
                "variants"=> array(
                    array(
                        "price"=> ($product->getPrice()),
                        "sku"=> $product->getsku()
                    )
                ),
                "images"=> $images
            )
        );

Upvotes: 0

Views: 217

Answers (1)

Srdjan Pejic
Srdjan Pejic

Reputation: 8202

You can't create a product and assign it to a collection in a single REST API call.

The best you can do is create the product first and upon its success, create a "collect", which is a mapping between a collection and a product.

See this API page for info on how to do that, Custom collection update.

Upvotes: 1

Related Questions