# Curl API error using PHP

**URL:** <https://community.swiftype.com/t/curl-api-error-using-php/779>\
**Category:** API\
**Created:** [July 16, 2018, 9:50am UTC](https://community.swiftype.com/t/curl-api-error-using-php/779 "2018-07-16T09:50:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![maulik.paddhariya](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@maulik.paddhariya](https://community.swiftype.com/u/maulik.paddhariya)\
**Post date:** [July 16, 2018, 9:50am UTC](https://community.swiftype.com/t/curl-api-error-using-php/779/1 "2018-07-16T09:50:53Z")

</div>

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](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
