M
M
mirexdoors2019-08-27 06:34:23
Bitrix24
mirexdoors, 2019-08-27 06:34:23

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

I pass the resulting array to a custom field with the "fileData" key:
$arParams['UF_CRM_1566289984628'] = ['fileData' => $fileData ];

I create a lead - the lead is successfully created, but the file is not attached. No error is generated. Perhaps it still somehow depends on the user's rights in the CRM?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mirexdoors, 2019-08-29
@mirexdoors

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.

A
Artem, 2019-08-27
@artemky

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 question

Ask a Question

731 491 924 answers to any question