I
I
IgorPlays2021-09-10 09:31:39
PHP
IgorPlays, 2021-09-10 09:31:39

Can't add a custom field to a deal?

I have a code that adds a deal to amocrm through their php library,
I do everything according to the docs, but it gives an error

$externalData = [
    [
        'is_new' => true,
        'name' => $title,
        'tag' => $leadId,
        'external_id' => '0752a617-c834-4bde-b4a6-76ff0fe26871',
    ]
];

$leadsCollection = new LeadsCollection();


foreach ($externalData as $externalLead) {
    $lead = (new LeadModel())
        ->setName($externalLead['name'])
        ->setPrice($externalLead['price'])
        ->setTags(
            (new TagsCollection())
                ->add(
                    (new TagModel())
                        ->setName($externalLead['tag'])
                )
        )
        ->setRequestId($externalLead['external_id']);
    
    $leadCustomFieldsValues = new CustomFieldsValuesCollection();
 
    $textCustomFieldValuesModel = new TextCustomFieldValuesModel();
    
    $textCustomFieldValuesModel->setFieldId(1200597);
    
    $textCustomFieldValuesModel->setValues(
    (new TextCustomFieldValueCollection())
        ->add((new TextCustomFieldValueModel())->setValue('Текст'))
    );
    
    $leadCustomFieldsValues->add($textCustomFieldValuesModel);

    $lead->setCustomFieldsValues($leadCustomFieldsValues);
    $leadsCollection = new LeadsCollection();
    $leadsCollection->add($lead);
}


*Variables and id are all spaced out*

their documentation > https://github.com/amocrm/amocrm-api-php#%D1%80%D0...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IgorPlays, 2021-09-13
@IgorPlays

$leadCustomFieldsValues = new CustomFieldsValuesCollection();   
 $field= new TextCustomFieldValuesModel();
    $field->setFieldId(010101);
    $field->setValues(
        (new TextCustomFieldValueCollection())
            ->add((new TextCustomFieldValueModel())->setValue("Text")
    );

$leadCustomFieldsValues->add($field);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question