Inserting ID with POST request is not allowed

Hi, i have a problem when i want to add an id in my post request. I use node.js. So this is my code.

async function addPersonInOnePipeDriveOrganization(capsule) {
logger.debug('addPersonInOnePipeDriveOrganization function');

// Find the id of the user's organization.
const id = await getOrganizationIDByName(capsule);
const user_id = await getPersonIDByName(capsule);

const data = {
    id, // Id of the organization
    user_id, // Id of the user
};

return new Promise((resolve, reject) => pipedrive.Persons.add(data, (err, person) => {
    if (err) return reject(err);
    logger.debug(`Person added with success ${JSON.stringify(person)}`);
    return resolve(person);
}));

}

And this is my function for get the organization id, this is the same function for get the person id.

async function getOrganizationIDByName(capsule) {
logger.debug('getOrganizationIDByName function');

const search = pipedrive.SearchResults.field({
    term: get(capsule, 'sessionMemory.companyName'),
    exact_match: true,
    field_key: 'name',
    field_type: 'organizationField',
    return_item_ids: true,
}, (err, data) => {
    if (err) throw err;
    logger.warn(data);
});

const result = await requestPromise({
    uri: search.url.href,
    method: 'GET',
    json: true,
});

logger.debug('--------- RESULT -> ORGANISATION ID ------------');
logger.debug(result.data[0].id);

return result.data[0].id;

}

This is the complet error:

Error: Pipedrive API error:Inserting ID with POST request is not allowed. If you have any questions, please contact Pipedrive support

I think it’s my bad but i don’t find the solution …

Thank you for your help.

The problem is here

const data = {
    id, // Id of the organization
    user_id, // Id of the user
};

Like the error message says, you can’t pass the id when you’re adding an object. The id is generated automatically and returned in the response.

Also, the organization id is called org_id.

So try this:

const org_id = await getOrganizationIDByName(capsule);

const data = {
    org_id: org_id, // Id of the organization
};

Let me know if it helps…

2 Likes

Hello Dani,

Sorry for the long time of my response … So, i succeeded to add an person to an organization ! Thank you for your help. This is my final code:

async function addPersonInOnePipeDriveOrganization(organisation, person) {
logger.debug('addPersonInOnePipeDriveOrganization function');

logger.debug(`Organisation ID : ${organisation.id}`);
logger.debug(`Person ID : ${person.id}`);

const data = {
    org_id: organisation.id, // Id of the organization
    name: person.name, // Name of the user
};

return new Promise((resolve, reject) => pipedrive.Persons.add(data, (err, _person) => {
    if (err) return reject(err);
    logger.debug(`Person added with success ${JSON.stringify(_person)}`);
    return resolve(_person);
}));

}

Noted, he don’t wait an user_id but the user’s name and the org_id for the organization id.

Thank you again, your response was very helpful !

2 Likes