intercom / intercom-node

Node.js bindings for the Intercom API
https://developers.intercom.com
Other
366 stars 116 forks source link

500 Response When Trying to Search For Contact #344

Closed mSigson closed 1 year ago

mSigson commented 1 year ago

Version info

Expected behavior

Able to successfully search for an intercom contact via the intercom.contacts.search client method

Actual behavior

Getting a 500 response when trying to search for a contact

Steps to reproduce

service

import { ContactObject, Operators, MessageObject } from "intercom-client";
import intercom from "services/intercom/client";

...

await intercom.contacts.search({
      data: {
        query: {
          field: "email",
          operator: Operators.AND,
          value: email,
        },
      },
    });

client

import { Client } from "intercom-client";

const client = new Client({
  tokenAuth: { token: process.env.INTERCOM_ACCESS_TOKEN || "" },
});

export default client;

Logs

Error: Server Error
    at new BadResponseError (.../node_modules/.pnpm/intercom-client@4.0.0_debug@4.3.4/node_modules/intercom-client/dist/errors/badResponse.error.js:22:28)
    at Client.checkOnErrorInResponse (...node_modules/.pnpm/intercom-client@4.0.0_debug@4.3.4/node_modules/intercom-client/dist/client.js:308:16)
    at Client.<anonymous> (...node_modules/.pnpm/intercom-client@4.0.0_debug@4.3.4/node_modules/intercom-client/dist/client.js:218:36)
    at step (...node_modules/.pnpm/intercom-client@4.0.0_debug@4.3.4/node_modules/intercom-client/dist/client.js:52:23)
    at Object.throw (...node_modules/.pnpm/intercom-client@4.0.0_debug@4.3.4/node_modules/intercom-client/dist/client.js:33:53)
    at rejected (...node_modules/.pnpm/intercom-client@4.0.0_debug@4.3.4/node_modules/intercom-client/dist/client.js:25:65)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  body: {
    type: 'error.list',
    request_id: '00001icmrd6nrb6r0eng',
    errors: [ { code: 'server_error', message: 'Server Error' } ]
  },
  headers: {
    date: 'Mon, 30 Jan 2023 03:06:59 GMT',
    'content-type': 'application/json; charset=utf-8',
    'transfer-encoding': 'chunked',
    connection: 'close',
    status: '500 Internal Server Error',
    'cache-control': 'no-cache',
    'x-ratelimit-limit': '167',
    'x-ratelimit-reset': '1675048022',
    'strict-transport-security': 'max-age=31556952; includeSubDomains; preload',
    'x-ratelimit-remaining': '167',
    vary: 'Accept,Accept-Encoding',
    'x-intercom-version': 'e132fec50b7db29ad8713de6abd34b93261c8be2',
    'x-xss-protection': '1; mode=block',
    'x-request-id': '00001icmrd6nrb6r0eng',
    'intercom-version': '2.7',
    'x-runtime': '0.107703',
    'x-frame-options': 'SAMEORIGIN',
    'x-content-type-options': 'nosniff',
    server: 'nginx'
  },
  statusCode: 500
}
colmdoyle commented 1 year ago

@mSigson - Thanks for getting in touch! We'll review this and get back to you ASAP.

colmdoyle commented 1 year ago

Just did some quick digging.

First off, thanks again for the report, the SDK definitely should handle this better.

To your actual issue, the reason a 500 is being thrown appears to be because you're passing an AND operator, but only one query. AND should be used for combining queries. I assume you might be trying to do something like

    const query = await client.contacts.search({
        data: {
          query: {
            field: "email",
            operator: intercom.Operators.CONTAINS,
            value: '@intercom.io',
          },
        },
      });
colmdoyle commented 1 year ago

I've created an issue to track some changes we could make to improve the error handling here, but I think double checking your query string should solve your problem.

If not, reopen this and we can dig further.

mSigson commented 1 year ago

Thank you for the fix and quick response @colmdoyle ! Silly mistake on my end 🙏