# Workflow custom code - doSearch not returning results

**URL:** <https://community.hubspot.com/t/workflow-custom-code-dosearch-not-returning-results/76357>\
**Category:** APIs & Integrations\
**Tags:** workflows, contacts\
**Created:** [March 2, 2023, 2:30pm UTC](https://community.hubspot.com/t/workflow-custom-code-dosearch-not-returning-results/76357 "2023-03-02T14:30:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LDev7](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@LDev7](https://community.hubspot.com/u/LDev7)\
**Post date:** [March 2, 2023, 2:30pm UTC](https://community.hubspot.com/t/workflow-custom-code-dosearch-not-returning-results/76357/1 "2023-03-02T14:30:27Z")

</div>

We are trying to retrieve a contact to update by using a custom parameter that is passed into the custom code section of a workflow.

const hubspotClient = new hubspot.Client({  
accessToken: process.env.ACCESS\_KEY  
});

const referrer\_ = event.inputFields[‘referrer\_’];

const filterGroup = {  
filters: [{  
propertyName: ‘referrer\_id’,  
operator: ‘EQ’,  
value: referrer\_  
}]  
}

const properties = [‘referrer\_id’, ‘total\_referrals’, ‘firstname’, ‘lastname’, ‘email’]

const publicObjectSearchRequest = {  
filterGroups: [filterGroup],  
properties  
}

hubspotClient.crm.contacts.searchApi.doSearch(publicObjectSearchRequest).then(results =\> {

let contactId = results.body.results[0].id; // Id of the referring contact  
let referred\_by = results.body.results[0].properties.firstname + " " + results.body.results[0].properties.lastname;

}

The referrer\_ variable contains the correct value but the doSearch never returns any results. I’ve also tried just searching for the contact by email with the correct email hardcoded into the query but i still receive nothing back. Is there something else i should be doing?

---

<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:** [March 2, 2023, 10:14pm UTC](https://community.hubspot.com/t/workflow-custom-code-dosearch-not-returning-results/76357/2 "2023-03-02T22:14:02Z")

</div>

Hi, @LDev7 👋 Let’s dig into the search operator part of things, and we can go from there 🏎

The EQ filter is strict. Unless you literally have a Contact with an exact value of “referrer\_” for the Referrer ID property, I’m not surprised it’s coming back with zero results.

Can you try the CONTAINS\_TOKEN operator instead, please?

I ran a quick test and got back a successful result.  
PS, I made a few assumptions on your exact setup, but I think I got close:

- I created a custom property called “referrer id” and gave it an internal value of referrer\_id

 ![CleanShot 2023-03-02 at 15.00.47.png](https://d2qpr2jzcazej7.cloudfront.net/original/1X/188d0af00e0f5991248341ed7ef1847f4dbb8192.png)

- I assigned this property to three contacts. Not only that, but I wasn’t certain if you were concatenating an additional string to each Contact’s value for the property — meaning I chose to do it like “referrer\_id\_123”, for example.

 ![CleanShot 2023-03-02 at 15.05.24.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/4/c413b9d39370d7b2163ac896f55671ec40885672.png)

- My Search API request (using Postman)  
Endpoint [https://api.hubapi.com/crm/v3/objects/contacts/search](https://api.hubapi.com/crm/v3/objects/contacts/search)  
Request body

- Response

- These three Contacts match the three shown in my filtered view

If I missed anything, or you have additional details to share, please let me know!

Have fun building! — Jaycee

---

<div class="post-metadata">

**Author:** ![LDev7](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@LDev7](https://community.hubspot.com/u/LDev7)\
**Post date:** [March 3, 2023, 12:13pm UTC](https://community.hubspot.com/t/workflow-custom-code-dosearch-not-returning-results/76357/3 "2023-03-03T12:13:23Z")

</div>

Hi Jaycee,

Thanks for the reply. The referrer\_ value is a variable that is assigned a value from the input field. In this case a 5 digit number. This number matches exactly with the referrer\_id property on the contact record.

This appears to be working now. The issue i now have is retrieving the data from the results. I would like the firstname property in the result to add to a variable.

An example i had been given was to use: let referred\_by = results.body.results[0].properties.firstname

but when doing this i get this error

`"errorMessage":"TypeError: Cannot read properties of undefined (reading 'results')"`

If i just do a console.log of the results i get this:

```auto
CollectionResponseWithTotalSimplePublicObjectForwardPaging {
 total: 1,
 results: [
 SimplePublicObject {
 id: '121129001',
 properties: [Object],
 createdAt: 2022-08-11T07:07:09.744Z,
 updatedAt: 2023-03-02T12:28:02.242Z,
 archived: false
 }
 ]
}

```

Is there a way to access the properties to use them in the custom code?

Thanks again

---

<div class="post-metadata">

**Author:** ![LDev7](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@LDev7](https://community.hubspot.com/u/LDev7)\
**Post date:** [March 3, 2023, 12:30pm UTC](https://community.hubspot.com/t/workflow-custom-code-dosearch-not-returning-results/76357/4 "2023-03-03T12:30:06Z")

</div>

Ah i’ve got it, just need to remove the .body from the code.

So instead of let referred\_by = results.body.results[0].properties.firstname

it should be let referred\_by = results.results[0].properties.firstname.

thanks for your help, it all appears to be working now
