Error during using api of "addPerson(params)"

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
});

Thanks for reporting the issue @okrupnik13 & welcome to the community :wave: !
I faced similar challenges when running the code. I am checking it with the engineering team currently if there’s an issue on our end. :slight_smile:

Thanks. I’ll be waiting for the results.

Hey!
We pushed out a fix for this issue in 13.1.3. Feel free to try it out.
FYI: there still is an issue with custom fields regarding this function.

Here’s a REPL where you can try it out

1 Like

Hi! Great, I will try it.
I also want to ask about the phone. Is there an opportunity to get a phone for a new person like “Pipedrive.BasicPersonPhone.constructFromObject({value:”+375791112233", label:“work”});"
or can I use “BasicPersonPhone”, as far as I understood that the structure of mail and phone for the request is the same?

I tried using “Pipedrive.BasicPersonEmail.constructFromObject” for the email and phone of the creating person. And it works in both cases

1 Like