HubSpot / hubspot-api-nodejs

HubSpot API NodeJS Client Libraries for V3 version of the API
Apache License 2.0
311 stars 101 forks source link

DoSearch is not working? #226

Closed lddtandil closed 2 years ago

lddtandil commented 2 years ago

Hi everyone I am not being able to make the doSearch function work What am I doing wrong? The code is in the README instructions (https://github.com/HubSpot/hubspot-api-nodejs) I'm receiving this message error: "message: 'Invalid input JSON on line 1, column 102: Cannot build Filter, some of required attributes are not set [propertyName, operator]',"

        const filter = { propertyName: 'createdate', operator: 'GTE', value: `${Date.now() - 30 * 60000}` }
        const filterGroup = { filters: [filter] }
        const sort = JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })
        const query = 'test'
        const properties = ['createdate', 'firstname', 'lastname']
        const limit = 100
        const after = 0

        const publicObjectSearchRequest = {
            filterGroups: [filterGroup],
            sorts: [sort],
            query,
            properties,
            limit,
            after,
        }

        try {
            hubspotClient.crm.contacts.searchApi.doSearch(publicObjectSearchRequest)
            .then((results) => {
          ...
            });

        } catch (e) {
          ...
        }
hellish commented 2 years ago

Same for me.

Body

{
  "status": "error",
  "message": "Invalid input JSON on line 1, column 102: Cannot build Filter, some of required attributes are not set [propertyName, operator]",
  "correlationId": "5c47f0ec-50e2-47ac-8fd4-651a1ccf913b"
}

Headers

{
  "access-control-allow-credentials": "false",
  "alt-svc": "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400",
  "cf-cache-status": "DYNAMIC",
  "cf-ray": "72465dbf7bddd2f4-LCA",
  "connection": "close",
  "content-length": "213",
  "content-type": "application/json;charset=utf-8",
  "date": "Sat, 02 Jul 2022 09:31:03 GMT",
  "expect-ct": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
  "nel": "{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}",
  "report-to": "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=ZJJAGAhen1PCytNDF4x1UREmSoOHvZIdcNG2woRNWBQyjm8sfKweHWTxA6kcAbnbLywSk6KEVkH56S%2FG%2B8GAzCMbSkprfX6SRwHhLUCYUmvydoovCpxrYU9ZXsOuStUU\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
  "server": "cloudflare",
  "strict-transport-security": "max-age=31536000; includeSubDomains; preload",
  "vary": "Accept-Encoding",
  "x-hubspot-correlation-id": "5c47f0ec-50e2-47ac-8fd4-651a1ccf913b",
  "x-hubspot-ratelimit-daily": "250000",
  "x-hubspot-ratelimit-daily-remaining": "249972",
  "x-trace": "2B6BBD07D40C87C1B5D1A810F5A89ECE6138D24909000000000000000000"
}
Paul-Bird commented 2 years ago

Is the problem operator is not in quotes https://developers.hubspot.com/docs/api/crm/search. you are using JSON.stringify for the sort but not for the filter.

ksvirkou-hubspot commented 2 years ago

Hi everyone, I've just checked it on SDK version 7.1.2 and It works fine.

const publicObjectSearchRequest = {
  filterGroups: [{ filters: [ { propertyName: 'createdate', operator: 'GTE', value: `${Date.now() - 30 * 60000}` } ] }],
  sorts: [{ propertyName: 'createdate', direction: 'DESCENDING' }],
  query: 'for',
  properties: ['createdate', 'firstname', 'lastname'],
  limit: 100,
  after: 0,
}

const result = await hubspotClient.crm.contacts.searchApi.doSearch(publicObjectSearchRequest)
console.log(JSON.stringify(result))
okachanov commented 1 year ago

Still reproduces on 8.2.0 for crm.deals.searchApi.doSearch

Request body: { filterGroups: [{ filters: [ { propertyName: 'dealname', operator: 'IN', values: ['TEST'] }, ] }], properties: ['createdate', 'dealname'], sorts: [JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })], limit: 10, after: 0, }

Response body: { status: 'error', message: 'Invalid input JSON on line 1, column 98. Some required fields were not set: [propertyName, operator]', correlationId: '4b628bf3-f10d-4459-b6e5-2163480a9931', category: 'VALIDATION_ERROR' }

ksvirkou-hubspot commented 1 year ago

Still reproduces on 8.2.0 for crm.deals.searchApi.doSearch

Request body: { filterGroups: [{ filters: [ { propertyName: 'dealname', operator: 'IN', values: ['TEST'] }, ] }], properties: ['createdate', 'dealname'], sorts: [JSON.stringify({ propertyName: 'createdate', direction: 'DESCENDING' })], limit: 10, after: 0, }

Response body: { status: 'error', message: 'Invalid input JSON on line 1, column 98. Some required fields were not set: [propertyName, operator]', correlationId: '4b628bf3-f10d-4459-b6e5-2163480a9931', category: 'VALIDATION_ERROR' }

Please create a new Issue or reopen this one. I'll check your case on Monday.

ksvirkou-hubspot commented 1 year ago

It returns no errors but I can't get the expected deal. The problem seems to be on the API side. CC @okachanov

gmunguia commented 1 year ago

I have the same issue. However, sending the same payload through hubspotClient.apiRequest works.