Curl API error using PHP


#1

Hi ,
I am trying create a document type using API in PHP language so i have create below code but its appear error and i cant understand how to resolve this . sorry i am newbie.
Here is the my code
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, “https://api.swiftype.com/api/v1/engines/khp1/document_types.json”);
$data = array(
‘auth_token’ => ‘KEY’,
‘document_type’ => array(‘name’ => ‘books’),

	);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_POST, true);
  	curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
	curl_setopt($ch,CURLOPT_HEADER, 0);
    $result = curl_exec($ch);
   
    curl_close($ch);
      
    print_r(json_decode($result));

Error : Invalid record. message: Validation of DocumentType failed. summary: The following errors were found: Name is already taken resolution: Try persisting the document with valid data or remove the validations

please help me