Pulling through companies - looking for ones that are specifically 'targeted' accounts

Howdy folks,

I’m currently working to build an application that integrates the Hubspot API. I’ve got OAuth up and running and was able to pull through all the companies for an authenticated account. However, I have two questions, on about the API, and one about the Node hubspot client that was recommended in the API docs.
1. Currently, I’m trying to pull through all the companies, and then of those, find the ones that show in the ‘Targeted Accounts (Beta)’ section of the Hubspot website. As I understand it, in order to do this I need to be looking for/requesting a specific property to be included with the returned companies in order to do this. I’ve tried looking asking for the ‘hs_target_account’ property, but when I do that none of the companies I get back have properties defined. But if I request the ‘name’ for example, I get all the name information for all the companies, as you’d expect. Does anyone know if this is just because it’s a beta feature? Or am I using the incorrect property name here?
2. This is more of a general question about the recommended hubspot client for Node from the docs. I’ve read through their documentation in the repository, and it’s not super in-depth. When using the hubspot.companies.get(opts) method - how do I include multiple properties? In the API docs it says to include the properties query param multiple times in the request URL. However, when using the client, you just pass an object, with ‘properties’ as a key. If I pass just one property it’s fine, but if I try to pass multiple, like ‘name hs_target_account website’ or ‘name, hs_target_account, website’ it fails to return anything. Presumably, because it’s not parsing those properties into multiple different query params under the hood. Anyone have experience working with this client and know how to do that?
Thanks!

Hey @ZamurphDev,

Let’s walk through your query one by one!

1. Do you mind sharing with me an example company in the ‘Targeted Accounts (Beta)’ and the following so that I can further dig into things on my end:

- Portal ID

- The exact request endpoint that you’re using

2. To clarify, how are you including multiple properties on the request URL? Do you have an example of your request url?

Hey Wendy,

Happy to walk through this.

So the I am attempting to pull data from an account with the portal ID 1917620. This account has 6 accounts that show up under the ‘Targeted Accounts (Beta)’.
As far as the endpoint, I am actually using the node HubSpot client found here: GitHub - HGData/mk-node-hubspot: Node wrapper for the HubSpot API · GitHub

This was the client recommended in the documentation, though, I don’t think it’s an official client so I understand if you’re not able to provide support for it. I am using the hubspot.companies.get() method and passing the following parameters as a JavaScript Object: {properties: ‘name’, limit: 250} - this works, but if I tried to request multiple properties, like this: {properties: ‘name hs_is_target_account’, limit: 250} it fails (returns the companies still, but all of the properties on the companies are empty.)

For what it’s worth, I did some digging into this on my own, and when logged into an account that has access to the Targeted Accounts (Beta), if I navigate there through HubSpot’s website in a browser using the navbar - the browser makes a POST request to the following endpoint https://api.hubspot.com/contacts/search/v1/search/companies/v2?portalId=1917620&clienttimeout=60000 and makes use of a filter object attached to the request which appears to be how it’s getting at the data that I am looking for. I glanced at the docs for both the v1 and v2 API’s that ya’ll provide and wasn’t able to find documentation on this endpoint.

If you can point me in the right direction, that’d be greatly appreciated!

Hey @ZamurphDev,

Just to clarify, are you looking to retrieve account that are under ‘Targeted Accounts (Beta)’? Specifically the 6 accounts.

If so, I’d suggest for you to use the CRM v3 API as it allows you to search and filter CRM objects.

Here’s an example:

POST https://api.hubspot.com/crm/v3/objects/companies/search?hapikey={{hapikey}}

POST body

{
 "filterGroups":[
 {
 "filters":[
 {
 "propertyName": "hs_is_target_account",
 "operator": "EQ",
 "value": "true"
 }
 ]
 }
 ]
 }

Awesome, that’s correct and looks like it should work. I’ll mark your reply as the solution once I test it. Just to confirm, this will work with OAuth as opposed to the API key as well, correct?

I think this will endpoint will also work for retrieving all companies with multiple properties - i.e. name and website, is that correct?

Hey @ZamurphDev,

That is right! This will work with OAuth and HAPI Key.

This endpoint will also work for retrieving all companies with multiple properties set.

Awesome, thanks Wendy. I have just one more question - can we get emails associated with a company, or do you have to get the contacts associate with that company and then pull the emails off of those contacts? Also, you’ve been a huge help, so thank you very much. :slightly_smiling_face:

Hey @ZamurphDev,

You’re most welcome :slightly_smiling_face:

When looking to get emails associated with a company, you’re spot on! As the email property is a contact property, you’d need to get the contact associated with the company and pull the email from there.

One other workaround is to copy the contact email property value to a company email property (you can create a custom company property for this) using a workflow and here’s a useful guide on how you can implement this setup: Working Around Workflows: A Guide to Copying Property Values.

Great, thank you!

Also, sorry for the late reply, but I do have another question (might have a few more as they come up, and will just bump this thread as necessary - if that’s OK?) currently the CRM API only allows for three filters per filter group. If I wanted to query for more than just 3 AND properties - is there an easy way to do this? Currently, it seems like the only way to do this would be to have some kind of logic on my end that will filter the return values, but my concern is that editing the returned values on my end might interfere with pagination (by changing the indexes/values in the returned data.)
Thanks again!

Hey @ZamurphDev,

In this case, have you explore the option of creating a contact list and using the Get contacts in a list | Contact Lists API? This might work better for your use case if you’re looking to set more filters.

Hey Wendy!
I am using contact lists for contacts, but the filtering question/issue was about getting companies using more than just 3 filters. Sorry if that wasn’t clear and than you as always for your reply. :slightly_smiling_face:

Hey @ZamurphDev,

Thanks for the further clarification!

In this case, are you looking to have more than three filterGroups? If so, that’s not possible. However, you should be able to have 3 filterGroups in which it consists 3 filters as stated on this documentation:

The system supports a maximum of three filterGroups with up to three filters each.