# Создание билета через api (пример на php)

**URL:** <https://community.itop-itsm.ru/t/sozdanie-bileta-cherez-api-primer-na-php/430>\
**Category:** Использование\
**Created:** [11.Август.2016 08:26:21 UTC](https://community.itop-itsm.ru/t/sozdanie-bileta-cherez-api-primer-na-php/430 "2016-08-11T08:26:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander](https://community.itop-itsm.ru/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@Alexander](https://community.itop-itsm.ru/u/Alexander)\
**Post date:** [11.Август.2016 08:26:21 UTC](https://community.itop-itsm.ru/t/sozdanie-bileta-cherez-api-primer-na-php/430/1 "2016-08-11T08:26:21Z")

</div>

Возникла задача - создать user request в iTop со стороннего сервиса. Вот пример кода на PHP может кому-нибудь пригодится, чтобы меньше разбираться:

* * *

```
curl_setopt($curl, CURLOPT_URL, 'https://адрес_сервиса/webservices/rest.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);

$arr = array('operation' => 'core/create', 'comment' => 'auto creation for cloud', 'class' =>

```

‘UserRequest’, ‘output\_fields’ =\> ‘id, friendlyname’, ‘fields’ =\> array(‘org\_id’ =\> 2, ‘service\_id’  
=\> 8, ‘servicesubcategory\_id’ =\> 8 ,‘title’ =\> ‘api auto creation’, ‘description’ =\> ‘cloud test  
api’, ‘caller\_id’ =\> array(‘name’ =\> ‘xxx’, ‘first\_name’ =\> ‘xxx’)));  
$sd = json\_encode($arr);

```
curl_setopt($curl, CURLOPT_POSTFIELDS, "version=1.3&auth_user=ххх&auth_pwd=ххх&json_data=".$sd."");
$out = curl_exec($curl);

```

// $data = json\_decode($out);

```
print $out;

```

* * *
