Documentation

crm.item.add

Scope: catalog Permissions to execute: for all

crm.item.add({entityTypeId: number, fields: ?{})

Method creates new SPA item with entityTypeId.

Standard checks, modifications and automatic actions are performed upon creating an item:

  • access permissions;
  • completed required fields;
  • stage-dependent required fields;
  • correct field data is checked;
  • fields are assigned default values;
  • automation rules are launched after saving.

Method returns result similar to the method crm.item.get for newly created item.

To upload file as custom field value, pass the array with the first item as file name and second - as base64-encoded file content.

Examples of fields for various queries can be viewed here.

Parameters

Parameter Description
entityTypeIdSPA ID.
fieldsItem field value. Optional parameter.

Examples

Example for adding a SPA item with file upload option

$Smart_Type_ID = 577;

$file_name_1 = 'test_file_img.jpg';
$file_name_2 = 'test_file_img_2.jpg';
$path_1 = 'folder/test_file_img.jpg';
$path_2 = 'folder/test_file_img_2.jpg';

// Encode files in base64
$base64image_1 = base64_encode(file_get_contents($path_1));
$base64image_2 = base64_encode(file_get_contents($path_2));

// Generate query
$param['act'] = "crm.item.add?" . http_build_query(array(
	"entityTypeId" => $Smart_Type_ID,
	"fields" => [
		'title' => 'Test',
		'company_id' => 57,
		'contact_ids' => [ 5, 7 ],
		'assigned_by_id' => 1,
		'ufCrm5_1641472560814' => 57, // type - list, 57 - a list variant ID
		'ufCrm5_1641472485686' => 'string',
		'ufCrm5_1641472326332' => 777,
		'ufCrm5_1643035938' => 5, // type - CRM binding
		// type - file, multiple
		'ufCrm5_1641473846006' => [
			'0' => [ $file_name_1, $base64image_1],
			'1' => [ $file_name_2, $base64image_2]
		],
	]
));


© «Bitrix24», 2001-2024