pipedrive / client-nodejs

Pipedrive API client for NodeJS
MIT License
205 stars 82 forks source link

Can't set email on addPerson endpoint #187

Closed tw1t611 closed 3 years ago

tw1t611 commented 3 years ago

I am trying to add a person with an email field on v11. https://github.com/pipedrive/client-nodejs/blob/v11/docs/PersonsApi.md#addPerson

I tried several combinations. Its fine, if its not implemented yet. Just to make sure, that the request was made properly:

const lib = require("pipedrive");
const defaultClient = lib.ApiClient.instance;
const apiToken = defaultClient.authentications.api_key;
apiToken.apiKey = "xxx";

const personsApi = new lib.PersonsApi();
const person = await personsApi.addPerson({
  newPerson: new lib.NewPerson("sadfasd", null, null, [
    "test098@test.de",
  ]),
})

Response:

email: Array(1)
0: {value: "", primary: true}

Expected:

email: Array(1)
0: {value: "test098@test.de", primary: true}
dmitriyeff commented 3 years ago

@tw1t611 hi!

NewPerson constructor expects only name parameter.

To add a new person with an email use a simple object that contains fields you want to fill. Here is an example:

const personsApi = new lib.PersonsApi();

    let opts = {
        newPerson: {
            name: 'Robin Good',
            email: 'robin@test.com'
        },
    };

    personsApi.addPerson(opts).then((data) => {
        console.log('API called successfully. Returned data: ' + JSON.stringify(data));

        res.send(JSON.stringify(data));
    }, (error) => {
        console.error(error);
    });

Expected result:

 "email": [
            {
                "value": "robin@test.com",
                "primary": true,
                "label": ""
            }
        ],
tw1t611 commented 3 years ago

Thank you very much, I'd really like that example in the docs. Closing now. :)