Hello. I have a question when creating a new user via api. I have the code in my app:
async createPerson() {
try {
const newPerson = {
name: firstName + ' ' + lastName,
email: convertToPipeDriveArrayValue(email),
phone: mainPhoneNumber ? convertToPipeDriveArrayValue(mainPhoneNumber) : [],
orgId: createdOrganization && createdOrganization.data ? createdOrganization.data.id : ''
};
let params = Pipedrive.NewPerson.constructFromObject(newPerson);
return await this.personApi.addPerson(params);
} catch (error) {
logger.error("Failed to create of pipeDrive person", error);
throw error;
}
}
function convertToPipeDriveArrayValue(data) {
return [{
'value': data,
'primary': true,
'label': 'work'
}]
}
incoming parameters have the following form:
params: New Person { name: 'Eeeeeee Ttttt', email: [ Basic Person Email { value: 'eeettttttt@www.com', primary: true, label: 'work' } ], phone: [], orgId: 21 }
but I get an error in the line:
return await this.personApi.addPerson(params);
[ERROR] app - [in undefined:createPerson] Failed to create of pipeDrive person [C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\ApiClient.js:702:47,
Array.map (<anonymous>),ApiClient.<anonymous> (C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\ApiClient.js:701:42),
ApiClient.replaceCamelCaseObj (C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\ApiClient.js:686:37),
ApiClient._callee$ (C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\ApiClient.js:549:46),
tryCatch (C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:63:40),
Generator.invoke [as _invoke] (C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:294:22),
Generator.next (C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:119:21),
asyncGeneratorStep (C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24),
_next (C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9),
C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7,
new Promise (<anonymous>),ApiClient.<anonymous> (C:\Users\Krupnik_O\git\welcome-api\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12),
ApiClient.callApi (C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\ApiClient.js:673:25),
PersonsApi.addPersonWithHttpInfo (C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\api\PersonsApi.js:121:29),
PersonsApi.addPerson (C:\Users\Krupnik_O\git\welcome-api\node_modules\pipedrive\dist\api\PersonsApi.js:134:19)
what is the reason for the error?
at the same time, if I leave only the name, then it is created well. The problem, as I understand it, is in email and phone.
According to your api client-nodejs/PersonsApi.md at master · pipedrive/client-nodejs · GitHub, they have an array format. But there is no example of how it should look.
can you give a complete example of all the properties for creating a new user in this method, according to your documentation:
Pipedrive.New Person.construct From Object({
// Properties that you want to update
});