MadKudu / node-hubspot

Node wrapper for the HubSpot API
MIT License
192 stars 157 forks source link

Incorrect typedefs #299

Open a-ogilvie opened 3 years ago

a-ogilvie commented 3 years ago

I found a typedef that does not match the actual function that it describes.

From /lib/list.js:

  getContacts(id, options) {
    if (!id) {
      return Promise.reject(new Error('id parameter must be provided.'))
    }

    return this.client.apiRequest({
      method: 'GET',
      path: `/contacts/v1/lists/${id}/contacts/all`,
      qs: options,
      qsStringifyOptions: { indices: false },
    })
  }

From /typescript/list.ts:

  getContacts(id: number): RequestPromise

Note that the actual function takes two arguments, but the typedef only describes one argument. This causes an error to be thrown when passing an options argument to `getContacts.

Are there other functions where the typedef is incorrect? Should I open a PR to bring these in sync?

kev-supapass commented 3 years ago

I've just found another typedef that is incorrect on tickets.

The ITicket type is correct for V3 of the hubspot api.

from /typescript/tickets.ts:

export interface ITicket {
  subject: string
  content: string
  due_date: number
  hs_ticket_priority: string
  hs_pipeline: number
  hs_pipeline_stage: number
}
....
create(data: ITicket): RequestPromise

but in /tickets.js:

  create(data) {
    return this.client.apiRequest({
      method: 'POST',
      path: '/crm-objects/v1/objects/tickets',
      body: data,
    })
  }

We're hitting the V1 of the hubspot api.

This version requires an array of objects with a name and value.

[
  {
    "name": "subject",
    "value": "This is an example ticket"
  },
  {
    "name": "content",
    "value": "Here are the details of the ticket."
  },
  {
    "name": "hs_pipeline",
    "value": "0"
  },
  {
    "name": "hs_pipeline_stage",
    "value": "1"
  }
]

So we can either change tickets.js to use V3, or change the type to match V1