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?