Shopify API custom collection creation fails with 500 error

I’m having trouble setting up a custom collection through the Shopify API using a PHP wrapper library. I can successfully retrieve product data and cart information, but when I try to create a new collection with specific product IDs, it keeps failing.

$collection_data = array(
    "custom_collection" => array(
        "title" => "MyNewCollection",
        "collects" => array(
            "product_id" => 12345678,
            "product_id" => 87654321
        )
    )
);

try {
    $result = $shopify_api('POST', '/admin/custom_collections.json', $collection_data, $headers);
    
    echo "Calls made: " . shopify_calls_made($headers);
    echo "Calls remaining: " . shopify_calls_left($headers);
    
} catch (ShopifyApiException $error) {
    echo "Request failed";
    var_dump($error);
}

The API returns a 500 Internal Server Error with just a generic “Error” message. Other API operations work fine, so I think there might be an issue with how I’m structuring the collection data. Has anyone successfully created collections this way? What am I missing in the request format?

Had this exact issue last month building a collection management feature. Your data structure’s the problem - you’re trying to create the collection and add products in one request, but Shopify’s API doesn’t work that way. Collections and collects are separate resources that need two steps. First, create the collection without the collects array, then use the Admin API’s collects endpoint to add products. Just send the title and other collection properties when creating. Once you get the collection ID back, make separate POST requests to /admin/collects.json for each product you want to add. This two-step approach fixed my 500 errors immediately. The API docs could be clearer about this, but once you get that collections and their product associations are managed separately, it makes way more sense from a REST perspective.

totally agree! i had the same issue too. the collects array is def wrong since you can’t have duplicate keys. just make the collection with basic fields and forget about adds in that call. it should fix the error.