# Incorrect Response from Custom Code in Workflow

**URL:** <https://community.hubspot.com/t/incorrect-response-from-custom-code-in-workflow/104552>\
**Category:** APIs & Integrations\
**Tags:** webhooks\
**Created:** [April 11, 2024, 12:25am UTC](https://community.hubspot.com/t/incorrect-response-from-custom-code-in-workflow/104552 "2024-04-11T00:25:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JKao2](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@JKao2](https://community.hubspot.com/u/JKao2)\
**Post date:** [April 11, 2024, 12:25am UTC](https://community.hubspot.com/t/incorrect-response-from-custom-code-in-workflow/104552/1 "2024-04-11T00:25:22Z")

</div>

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](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](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](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](https://www.premierworkspaces.com/hubfs/CER-1.jpg)”,  
“altText”: “”,  
“type”: “image”  
},  
“location\_url”: “[Cerritos Office Spaces | Premier Workspaces](https://www.premierworkspaces.com/california/cerritos)”,  
“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](https://g.page/PremierWorkspaces-Cerritos/review?rc)”,  
“email”: “[CERmanager@pbcenters.com](mailto: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?

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [April 11, 2024, 9:56pm UTC](https://community.hubspot.com/t/incorrect-response-from-custom-code-in-workflow/104552/2 "2024-04-11T21:56:20Z")

</div>

Hi, @JKao2 👋 Have you tried using something like `JSON.parse(searchResult.body)` instead?

Best,

Jaycee

---

<div class="post-metadata">

**Author:** ![JKao2](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@JKao2](https://community.hubspot.com/u/JKao2)\
**Post date:** [May 16, 2024, 5:58pm UTC](https://community.hubspot.com/t/incorrect-response-from-custom-code-in-workflow/104552/3 "2024-05-16T17:58:07Z")

</div>

i did eventually get this to work, but the code example from the hubspot sample github did not work for me

The code example from

[https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/hubdb\_table\_lead\_rotation.js](https://github.com/HubSpot/sample-workflow-custom-code/blob/main/samples/hubdb_table_lead_rotation.js)

asked me to do:  
.then(searchResult =\> {  
let salesRepsEmails = searchResult.body.results;

}

and from there being able to get the body and the results field  
but i did this instead  
.then((response) =\> response.json())  
.then((data) =\> {

console.log(data.results[0]);

}

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [May 16, 2024, 9:06pm UTC](https://community.hubspot.com/t/incorrect-response-from-custom-code-in-workflow/104552/4 "2024-05-16T21:06:57Z")

</div>

Hey, @JKao2 👋 Would you open an issue on GitHub, please? [Issues · HubSpot/sample-workflow-custom-code · GitHub](https://github.com/HubSpot/sample-workflow-custom-code/issues)

Thank you very much! — Jaycee
