Answer the question
In order to leave comments, you need to log in
How to pass Integer type parameter to REST API?
When accessing the Bitrix24 REST API from php, you need to pass the TASKID parameter
If I do it via cURL
$service_url = 'https://'.HomeController::DOMAIN.'.bitrix24.ru/rest/71/##############/task.item.getdata.json';
$curl = curl_init($service_url);
$data = array('TASKID' => $number);
$curl_post_data = array(
'content' => http_build_query($data)
);
$curl_post_data = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
dd($decoded);
queryUrl = 'https://'.HomeController::DOMAIN.'.bitrix24.ru/rest/71/#####################/task.item.getdata.json';
$data = array('TASKID' => $number);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($queryUrl, false, $context);
dd($result);
$result = json_decode($result, 1);
return $result;
Answer the question
In order to leave comments, you need to log in
You are not making the request correctly. You are not sending TASKID = 2, but a structure from content that contains json from http_build_query and the already needed array.
Replace:
$data = array('TASKID' => $number);
$curl_post_data = array(
'content' => http_build_query($data)
);
$curl_post_data = json_encode($curl_post_data);
$curl_post_data = array('TASKID' => $number);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question