Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Adding a Person #474

Open
tuliotrefzger opened this issue Jun 30, 2023 · 2 comments
Open

Problem Adding a Person #474

tuliotrefzger opened this issue Jun 30, 2023 · 2 comments

Comments

@tuliotrefzger
Copy link

Given the provided code:

import Pipedrive from 'pipedrive';
let apiClient = new Pipedrive.ApiClient();
// Configure API key authorization: api_key
let api_key = apiClient.authentications['api_key'];
api_key.apiKey = 'YOUR API KEY';
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key.apiKeyPrefix = 'Token';
// Configure OAuth2 access token for authorization: oauth2
let oauth2 = apiClient.authentications['oauth2'];
oauth2.accessToken = 'YOUR ACCESS TOKEN';

let apiInstance = new Pipedrive.PersonsApi(apiClient);
let opts = Pipedrive.NewPerson.constructFromObject({
  // Properties that you want to update
});
apiInstance.addPerson(opts).then((data) => {
  console.log('API called successfully. Returned data: ' + data);
}, (error) => {
  console.error(error);
});

I was not able to add a new person to Pipedrive. I kept getting this error:

TypeError: data.map is not a function
    at Function.convertToType (/var/task/node_modules/pipedrive/dist/ApiClient.js:1017:25)
    at Function.constructFromObject (/var/task/node_modules/pipedrive/dist/model/BasicPerson.js:72:48)
    at Function.constructFromObject (/var/task/node_modules/pipedrive/dist/model/NewPerson.js:73:33)
    at createPipedrivePerson (/var/task/functions/updateCrmInfo.js:247:36)

After some tries and errors, I found a solution that worked for me. I believe the error lies in the Pipedrive.NewPerson.constructFromObject() method. Here is the code that worked for me:

import Pipedrive from 'pipedrive';
let apiClient = new Pipedrive.ApiClient();
// Configure API key authorization: api_key
let api_key = apiClient.authentications['api_key'];
api_key.apiKey = 'YOUR API KEY';
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//api_key.apiKeyPrefix = 'Token';
// Configure OAuth2 access token for authorization: oauth2
let oauth2 = apiClient.authentications['oauth2'];
oauth2.accessToken = 'YOUR ACCESS TOKEN';

let apiInstance = new Pipedrive.PersonsApi(apiClient);
let opts = {
  // Properties that you want to update
};
const response = await apiInstance.addPerson(opts);
@bashmach
Copy link
Member

bashmach commented Jul 5, 2023

Hi @tuliotrefzger

Thank you for reporting an issue, and I'm glad there is a solution that worked for you 👍

Unfortunately I can't reproduce the issue from my side, but maybe you could provide us more details.
First of all it would be good to know what fields you're sending to API and version of SDK that you have.

This example works well for me with ^20.3

const api = new pipedrive.PersonsApi(defaultClient);
const opts = pipedrive.NewPerson.constructFromObject({
    name: 'John Doe',
    email: [{
        value: 'john@example.org',
        primary: false,
    }],
    org_id: 1,
    phone: [
        {
            value: '+380 123123123',
            label: 'mobile',
            primary: true,
        },
        {
            value: '+372 123123123',
            label: 'home',
            primary: false,
        },
    ],
    marketing_status: 'archived',
});

await api.addPerson(opts);

Looking forward to hearing back from you.

@y-nk
Copy link

y-nk commented Sep 1, 2023

this is crazy i was about to report exactly the same thing. @bashmach at least make a PR to update the docs please, it's been 2 months the issue is opened, the least you could do is correct the docs.

EDIT: the code provided doesn't work because the fields passed are snake cased (org_id but the docs mention camelcased fields orgId)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants