pipedrive / client-nodejs

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

`pipedrive.Deals.add` request times out with no response or error #104

Closed petedejoy closed 4 years ago

petedejoy commented 4 years ago

I have an express API that handles routing form submission data to Pipedrive via a series of 3 API calls:

  1. Create Org with company name.
  2. Create Person with name/email.
  3. Create Deal with both org and person associated.

Due to a reason that I can't identify, my pipedrive.Deals.add function began getting hung up and timing out yesterday. My deal does get created in Pipedrive, but no response or error is returned. I am also using Sentry to catch errors and see nothing in there. Here are the functions I use:

function createOrg(company) {
  return new Promise(resolve => pipedrive.Organizations.add({ name: company, owner_id: config.pipedrive.ownerId }, (err, decoded) => {
    if (err) {
      Sentry.captureException(new Error(err));
      return resolve({});
    }
    return resolve(decoded)}));
}

Completes successfully and returns the expected orgobject.

function createPerson(name, email, org_id) {
  return new Promise(resolve => pipedrive.Persons.add({ name, email, owner_id: config.pipedrive.ownerId, org_id }, (err, decoded) => {
    if (err) {
      Sentry.captureException(new Error(err));
      return resolve({});
    }
    return resolve(decoded)}));
}

Completes successfully and returns the expected persons object.

function createDeal(title, person_id, org_id, stage_id) {
  return new Promise(resolve => pipedrive.Deals.add({ title, user_id: config.pipedrive.ownerId, person_id, org_id, stage_id }), (err, decoded) => {
    if (err) {
      console.log(err);
      Sentry.captureException(new Error(err));
      return resolve({});
    }
    return resolve(decoded)});
}

Seems to complete (ie. deal is created in Pipedrive), but returns no response, doesn't log out any errors, and the API request hangs indefinitely. Could someone help point me to what's going wrong here? I suspect there is either a bug with this node package or that something is going on with the Pipedrive API's deals endpoint, but I could be handling something incorrectly in my code as well.

Note that this request did work as expected previously and I am almost certain nothing changed in my API code.

tot-ra commented 4 years ago

Did you try making API request from postman or other method, does it hang too?

petedejoy commented 4 years ago

Yes, I tried making the request to my API endpoint (which calls all of those functions sequentially) from both my website test environment and Postman.

tot-ra commented 4 years ago

If API hangs in postman too, then better to report it to support engineers, then we can trace / check logs of your company

petedejoy commented 4 years ago

@tot-ra what is the best channel to do that through?

tot-ra commented 4 years ago

Best one is support chat in the app https://support.pipedrive.com/hc/en-us/articles/115005875565

Optionally, there is also community forum that can also answer questions on API https://devcommunity.pipedrive.com/

petedejoy commented 4 years ago

It seems that the API endpoint is healthy. Commenting out the code that uses this library and using axios to post the /deals endpoint directly instead returns a successful and expected response:

function createDeal(title) {
  axios.post('https://<my-pipedrive-domain>.pipedrive.com/v1/deals?api_token=<my-api-token>', {
    title,
  }).then((res) => {
    console.log(`statusCode: ${res.statusCode}`)
    console.log(res)
  })
  .catch((error) => {
    console.error(error)
  })
  // return new Promise(resolve => pipedrive.Deals.add({ title }), (err, decoded) => {
  //   if (err) {
  //     Sentry.captureException(new Error(err));
  //     return resolve({});
  //   }
  //   return resolve(decoded)});
}

Note that all of the other functions I'm using from this package resolve as expected (pipedrive.Organizations.add, pipedrive.Persons.add).

eerootsus commented 4 years ago

@petedejoy Could it be you are making a lot of requests? There is some rudimentary rate limiting which tries to debounce the requests. I guess there might be a condition where requests pile up and will maybe be made far in the future.

Could you possibly monitor the x-ratelimit-* headers from the API responses and see what they look like just before you are seeing timeouts?

petedejoy commented 4 years ago

I really don't think I'm hitting a rate limit- I make like 3 requests a day. Another interesting thing is that, while changing the one deals function to use Axios instead of this library caused everything to run as expected, changing everything to Axios calls produces the same result as described here- the first two calls pass and the third gets hung up.

eerootsus commented 4 years ago

@petedejoy 🧐

Can you maybe try to turn on logging by setting PIPEDRIVE_DEBUG=true in your environment? And see what the output says? Also, as @tot-ra suggested, it might make sense to open a support ticket via support chat - we might have to track this issue on our server side and check the logs, but for that we need company account information, which should never be shared here.

RuTsEST commented 4 years ago

Closing this due to inactivity and the release of the new version of the client.