Reputation: 743
I have been trying to Add new Custom Collection Using Shopify API. But kept getting Error for title cannot be blank.
While Title is already being Set in POST fields
My Code is as below:
$url = 'https://APIKEY:[email protected]/admin/custom_collections.json';
$collection = array
(
"custom_collection" => array( 'title' => 'Made In the USA' )
);
// $payload = json_encode($collection);
$payload = '{
"custom_collection": {
"title": "IPods",
"collects": [
{
"product_id": 99395358
}
]
}
}';
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'HAC');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $payload);
$return = curl_exec( $ch );
curl_close( $ch );
I am getting response
{"errors":{"title":["can't be blank"]}}
Upvotes: 1
Views: 746
Reputation: 160963
CURLOPT_POSTFIELDS is in wrong format.
This parameter can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.
Upvotes: 1