Answer the question
In order to leave comments, you need to log in
How to attach a file to a lead via the API?
Hello! There was a problem when adding a file to a lead via api.
The data for the file is formed as follows:
$data = file_get_contents($url);
$base64 = base64_encode($data);
$fileName = urldecode(basename($url));
$fileData = [$fileName, $base64];
$arParams['UF_CRM_1566289984628'] = ['fileData' => $fileData ];
Answer the question
In order to leave comments, you need to log in
I'll answer the question myself, in case it's useful to someone.
When creating a lead by accessing "/crm/configs/import/lead.php", the file is loaded by specifying a direct link to the files available from the Internet for download.
The array, in my opinion, is composed correctly, the question is what do you have in $ url. I will attach the code that works for me for transactions:
$target = md5('salt'.$_FILES['spec_file']['name']);
$path = 'sales/upload/'.$target;
move_uploaded_file($_FILES['spec_file']['tmp_name'], $path);
$UF_CRM_1552985294 = array('fileData'=>array($_FILES['spec_file']['name'], base64_encode(file_get_contents($path))));
$CB24 = new CB24;
$cur_deal = $CB24->method('crm.deal.update.json',array(
"id" => $dealid,
"fields" => [
'UF_CRM_1552985294' => $UF_CRM_1552985294,
],
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question