I was following the code example to access hubdb in a custom code in a workflow
https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/hubdb_table_lead_rotation.js and the response was not outputting the JSON response that was expected.
i was making the call:
hubspotClient
.apiRequest({
method: ‘GET’,
path: `/cms/v3/hubdb/tables/3553671/rows?center_code=CER`
})
.then(searchResult => {
//print results
console.log(`RESULTS`);
console.log(searchResult.body.json);
//i am supposed to be able to get the body.results[0] if one exists but this errors out as the expected response isnt correct
// console.log(searchResult.body.results[0]);
callback({
outputFields: {
secret: process.env.APIKEY,
centercode: centerCode,
results: searchResult.body
}
})
});
and i was expecting the body of the result to be a JSON result, but it was outputting the following for the response:
{“_writeState”:{“0”:15346,“1”:0},“_readableState”:{“objectMode”:false,“highWaterMark”:16384,“buffer”:{“head”:{“data”:{“type”:“Buffer”,“data”:[123,34,116,111,116,97,108…
when it should have been a JSON output like when i put the same request in Postman:
{
“total”: 1,
“results”: [
{
“id”: “43221143852”,
“createdAt”: “2021-03-16T20:05:12.598Z”,
“updatedAt”: “1970-01-01T00:00:00Z”,
“publishedAt”: “2021-07-19T21:46:40.813Z”,
“values”: {
“zip”: “90703”,
“address”: “18000 Studebaker”,
“yelp_review_url”: “https://www.yelp.com/writeareview/biz/Z9yoaoq2OCxEndvnuZy9dA?return_url=%2Fbiz%2FZ9yoaoq2OCxEndvnuZy9dA&source=biz_details_war_button”,
“city”: “Cerritos”,
“bbb_review_url”: “https://www.bbb.org/us/ca/irvine/profile/executive-suites/premier-workspaces-1126-100062689/customer-reviews”,
“featured_image”: {
“url”: “https://www.premierworkspaces.com/hubfs/CER-1.jpg”,
“altText”: “”,
“type”: “image”
},
“location_url”: “Cerritos Office Spaces | Premier Workspaces”,
“local”: “33.86741,-118.0695”,
“center_code”: “CER”,
“phone”: “(562) 467-6900”,
“name”: “Cerritos Tower”,
“general_manager”: “Monica Mora”,
“state”: “CA”,
“google_my_business_review_url”: “Google Maps”,
“email”: “CERmanager@pbcenters.com”
},
“path”: null,
“name”: null,
“isSoftEditable”: false,
“childTableId”: “0”
}
],
“type”: “STREAMING”
}
In the code example i should be able to call .results[0].values.field_name but the response is not correct.
why is the body of the response not giving me back the expected JSON?