Encountering 'title can't be blank' error while creating a custom collection using Shopify API

I’m experiencing difficulties when trying to create a new custom collection with the Shopify API. Each time I attempt to send my request, I receive an error stating that the title cannot be blank, even though I am setting the title in my JSON payload.

Below is the code I’m working with:

$apiEndpoint = 'https://APIKEY:[email protected]/admin/custom_collections.json';

$dataArray = array(
    "custom_collection" => array(
        'title' => 'Home Decor'
    )
);

$requestPayload = '{
    "custom_collection": {
        "title": "Gadgets",
        "collects": [
            {
                "product_id": 98765432
            }
        ]
    }
}';

$curlSession = curl_init($apiEndpoint);
curl_setopt($curlSession, CURLOPT_POST, true);
curl_setopt($curlSession, CURLOPT_HEADER, false);
curl_setopt($curlSession, CURLOPT_USERAGENT, 'MyShopApp');
curl_setopt($curlSession, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curlSession, CURLOPT_TIMEOUT, 30);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $requestPayload);

$responseData = curl_exec($curlSession);
curl_close($curlSession);

The response from the API is:

{"errors":{"title":["can't be blank"]}}

Could someone please help me identify what might be wrong here?

yeah, you’re missing the Content-Type header in your curl request. shopify’s API needs it to read the json payload properly - without it, the title check gets skipped. add this line: curl_setopt($curlSession, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

Had this exact problem last month - drove me nuts for hours. You’re defining two payloads ($dataArray and $requestPayload) but only using the string version. The real issue though? Missing headers. Shopify treats your JSON as plain text without them. Fixed mine by setting both Content-Type and Accept headers: curl_setopt($curlSession, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json')); Also double-check you’re using the right API version endpoint if you’re on newer Shopify.