pipedrive / client-nodejs

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

Update custom field on Deal #193

Closed tw1t611 closed 3 years ago

tw1t611 commented 3 years ago

I need to update a custom field in a Deal.

I tried:

let deal = await lib.DealsController.addADeal({ ... })
deal = await lib.DealsController.updateADeal({
  id: deal.data.id,
  [dealFieldId]: deal.data.id,
})

The response does not show any hashes of custom fields. It works, when I omit [dealFieldId]: deal.data.id. Is this possible in another way in v10? I know, that zapier got it working somehow.

KristjanLuik commented 3 years ago

Hi @tw1t611

I'm using version pipedrive@10.6.1 and can be updated like so:

const lib = require('pipedrive');

lib.Configuration.apiToken = 'API_TOKEN';

const dealFieldId = '69b9b46432b6d23950fd2a696e5017f85b0972ab';

async function runExample() {
    let deal, updatedDeal;
    try {

        deal = await lib.DealsController.getDetailsOfADeal(262160);

        updatedDeal = await lib.DealsController.updateADeal({
            id: deal.data.id,
            [dealFieldId]: 'some nice custom field value 3',
        });
    } catch (error) {
        console.log(error)
    }

    console.log(updatedDeal);
}

runExample();

It results in: image

Some notes: 1) wrap your code in a try-catch to see error messages. 2) make sure your using the correct custom field hash, which can be copied here just to be safe -> https://app.pipedrive.com/settings/fields

tw1t611 commented 3 years ago

It somehow works now. Thanks for your help. Also thank you for the link. Closing now. :)