На всякий случай, если кто-нибудь наткнется на эти вопросы, вот как я решил свою проблему:
Я использовал «старую» конечную точку API <crm path>/service/v4/rest.php
и следующий (работающий, но урезанный!) Код:
Сначала небольшая модификация URL:
protected function curl($url, $get) {
$ch = curl_init();
$header = array(
// THIS IS DIFFERENT!
'Content-type: application/vnd.api+json',
'Accept: application/vnd.api+json',
);
$query = http_build_query($get);
$url = $url.'?'.$query;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output = curl_exec($ch);
return $output;
}
Теперь код аутентификации
$restData = [
'user_auth' => [
'user_name' => getenv('CRM_USERNAME'),
'password' => getenv('CRM_PASS_MD5'),
'version' => '1.2'
]
];
$get = [
'method' => 'login',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode($restData)
];
$output = curl($apiURL, $get); //@todo Connect the Api URL!
$data = json_decode($output);
$secret = $data->id; // This is what you need
Теперь для примера того, как получить данные:
function getData($secret) {
$restData = [
'session' => $secret,
//The name of the module from which to retrieve records
'module_name' => 'Tasks',
//The SQL WHERE clause without the word "where".
'query' => "",
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => '0',
//Optional. A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
'title',
'date_entered',
'date_modified',
'description',
'date_start',
'priority'
),
/*
A list of link names and the fields to be returned for each link name.
Example: 'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
*/
// 'link_name_to_fields_array' => array(
// ),
//The maximum number of results to return.
'max_results' => '999',
//To exclude deleted records
'deleted' => '0',
//If only records marked as favorites should be returned.
'Favorites' => false,
];
$get = [
'method' => 'get_entry_list',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode($restData)
];
$output = curl($this->apiUrl, $get);
$data = json_decode($output);}
return $data->entry_list;
}
И пример того, как вы устанавливаете данные
function setData($issueId, $field, $newValue) {
$restData = [
'session' => $this->secret,
//The name of the module from which to retrieve records
'module_name' => 'Tasks',
'name_value_list' => [
[
"name" => "id",
"value" => $issueId
],
[
"name" => $field,
"value" => $newValue
]
]
];
$get = [
'method' => 'set_entry',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode($restData)
];
$output = curl($apiUrl, $get);
$data = json_decode($output);
if (!$data) {
throw new \Exception('CRM invalid response!');
}
return true;
}