I need help with creating a product collection using the Shopify API
I’m working on building a custom collection through Shopify’s REST API but keep running into issues. I can successfully do other API operations like fetching products and managing shopping carts, but creating collections with specific product IDs just won’t work.
Here’s what I’m trying to do:
$collection_data = array(
"custom_collection" => array(
"title" => "MyNewCollection",
"collects" => array(
"product_id" => 12345678,
"product_id" => 87654321
)
)
);
try {
$result = $shopify_client('POST', '/admin/custom_collections.json', $collection_data, $headers);
echo shopify_calls_made($headers);
echo shopify_calls_left($headers);
echo shopify_call_limit($headers);
} catch (ShopifyApiException $error) {
echo "API call failed";
print_r($error);
}
The response I get back shows a 500 Internal Server Error with this exception:
ShopifyApiException Object
(
[info:protected] => Array
(
[method] => POST
[path] => /admin/custom_collections.json
[response_headers] => Array
(
[http_status_code] => 500
[status] => 500 Internal Server Error
[content-type] => application/json; charset=utf-8
)
[response] => Array
(
[errors] => Error
)
)
)
I’m following the official Shopify documentation but still getting stuck. Has anyone encountered this before or know what might be causing the internal server error? Any suggestions would be really helpful.