AmoCRM icon indicating copy to clipboard operation
AmoCRM copied to clipboard

TypeError: Cannot read properties of undefined (reading 'id')

Open blvckeasy opened this issue 2 years ago • 1 comments

// экземпляр Client const client = require('./client.js');

const run = async () => { /* базовые методы работы с объектом Lead описаны в интерфейсе ILead на сайте библиотеки https://usefulweb.github.io/AmoCRM/interfaces/api_activeRecords_Lead.ILead.html */ const lead = await client.leads.getById(123); lead.name = 'Ivan'; lead.price = 100;

await lead.save();

// вы можете менять и читать любые свойства сделки, которые передаются при её создании и обновлении
console.log(lead.id); // 123

/* Создание новой сделки */
const newLead1 = new client.Lead;

// является ли сделка новой (на основе наличия id у объекта)
lead.isNew(); // true

newLead1.name = 'Walter Scott';
await newLead1.save();
lead.isNew(); // false

// вы можете передать параметры сделки объектом
const newLead2 = new client.Lead({
    name: 'Walter Scott'
});
newLead2.price = 100;
await newLead2.save();

// ... спустя какое-то время сделка может обновиться на сервере
// fetch обновит параметры текущей сделки
const fetchedLead = await newLead2.fetch();

};

run();

/home/blvckeasy/node-apps/amocrm/node_modules/amocrm-js/dist/api/activeRecords/mixins/hasCreate.js:12 this.id = first.id; ^

TypeError: Cannot read properties of undefined (reading 'id') at HasEmbeddedTags. (/home/blvckeasy/node-apps/amocrm/node_modules/amocrm-js/dist/api/activeRecords/mixins/hasCreate.js:12:33) at Generator.next () at fulfilled (/home/blvckeasy/node-apps/amocrm/node_modules/tslib/tslib.js:166:62) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.13.0

blvckeasy avatar Mar 25 '24 08:03 blvckeasy

Получилось решить проблему?

Vladimir2011 avatar Nov 29 '24 09:11 Vladimir2011