Back to blog
7 min read

HubSpot Data Enrichment From Your Own API

By Kooperativa Engineering

HubSpot Data Enrichment From Your Own API

HubSpot's own enrichment is Breeze Intelligence, an in-product feature that fills contact and company properties from HubSpot's data sources. It is the right default for many teams. This article is for B2B revenue operations teams that want to enrich HubSpot from an API they control: a source they chose, a schedule they set and rules they wrote down.

The scope is professional fields: current employer, title and company id. Kooperativa holds no email addresses or phone numbers, so this does not replace a contact data tool, and nothing below adds either.

Where the code can run

There are three realistic places, and the choice is mostly about what your HubSpot plan allows.

OptionWhat it needsGood for
Custom code action in a workflowOperations Hub Professional or Enterprise, per HubSpot developer documentationEnriching one record when it is created or changes
Scheduled script outside HubSpotA private app token with contact read and write scopesWeekly re-checks of many records in batches
n8n or a similar toolThe same token and a node for each APITeams that already run their automation there

HubSpot's documentation lists the custom code action under Operations Hub Professional or Enterprise, on a page last modified in September 2025. Some versions of that page name Data Hub instead, so confirm the tier on your own plan page before you plan around it. The scheduled script below does not use workflows at all, so it does not depend on that tier.

Create the properties first

Give the script its own properties instead of writing into the standard ones. Create these on the contact object as single-line text:

  • kooperativa_profile_username: the key. The profile slug, set when a contact is matched.
  • kooperativa_company_id: the employer id the script last confirmed.
  • kooperativa_title: the current title the data returned.
  • kooperativa_status: baseline, verified, left_account or unmatched.
  • kooperativa_checked_at: the ISO date of the last check. Plain text avoids date formatting rules.

Keeping them separate means the script can never touch what a rep typed into Job Title. A workflow or a person decides when a verified title is copied across. The key is the one field you have to supply from outside: HubSpot does not guarantee a profile identifier on a contact, so collect it where you collect the contact, or propose candidates with people search and have a person confirm each one. Never write an unconfirmed match.

The sweep

The script reads every contact that has a username, enriches them 100 at a time, and writes the result back with a batch update. 100 is the bulk enrich limit and it keeps each HubSpot batch small. Check HubSpot's current batch limits before you raise it.

Sweep HubSpot contacts and write backjs
const KOO = 'https://kooperativa.io/api/v1';
const HS = 'https://api.hubapi.com/crm/v3/objects/contacts';
const kooHeaders = {
  Authorization: 'Bearer ' + process.env.KOOPERATIVA_API_KEY,
  'Content-Type': 'application/json',
};
const hsHeaders = {
  Authorization: 'Bearer ' + process.env.HUBSPOT_TOKEN,
  'Content-Type': 'application/json',
};

async function contactsWithKey() {
  const contacts = [];
  let after;
  do {
    const res = await fetch(HS + '/search', {
      method: 'POST',
      headers: hsHeaders,
      body: JSON.stringify({
        filterGroups: [
          { filters: [{ propertyName: 'kooperativa_profile_username', operator: 'HAS_PROPERTY' }] },
        ],
        properties: ['kooperativa_profile_username', 'kooperativa_company_id'],
        limit: 100,
        after,
      }),
    });
    if (!res.ok) throw new Error('HubSpot search failed: ' + res.status);
    const page = await res.json();
    contacts.push(...page.results);
    after = page.paging && page.paging.next ? page.paging.next.after : undefined;
  } while (after);
  return contacts;
}

export async function sweep() {
  const today = new Date().toISOString().slice(0, 10);
  const contacts = await contactsWithKey();

  for (let i = 0; i < contacts.length; i += 100) {
    const batch = contacts.slice(i, i + 100);
    const res = await fetch(KOO + '/people/bulk-enrich', {
      method: 'POST',
      headers: kooHeaders,
      body: JSON.stringify({
        profiles: batch.map((c) => ({ username: c.properties.kooperativa_profile_username })),
      }),
    });
    if (!res.ok) continue; // leave the batch for the next run

    const { profiles } = await res.json();
    const byName = new Map(profiles.map((p) => [p.username.toLowerCase(), p]));

    const inputs = batch.map((c) => {
      const stored = c.properties.kooperativa_company_id;
      const p = byName.get(c.properties.kooperativa_profile_username.toLowerCase());
      const properties = { kooperativa_checked_at: today };

      if (!p) {
        properties.kooperativa_status = 'unmatched';
      } else {
        if (p.current_title) properties.kooperativa_title = p.current_title;
        if (!stored) {
          properties.kooperativa_status = 'baseline';
          if (p.current_company_id) properties.kooperativa_company_id = p.current_company_id;
        } else if (p.current_company_id && p.current_company_id !== stored) {
          properties.kooperativa_status = 'left_account'; // flag it, leave the stored id alone
        } else {
          properties.kooperativa_status = 'verified';
        }
      }
      return { id: c.id, properties };
    });

    const upd = await fetch(HS + '/batch/update', {
      method: 'POST',
      headers: hsHeaders,
      body: JSON.stringify({ inputs }),
    });
    if (!upd.ok) console.error('HubSpot batch update failed', upd.status);
  }
}

Three choices in that script are deliberate. An unmatched contact is marked unmatched and nothing else changes, because a bulk call does not say why a person is missing and an absence is never proof that someone left. A company change sets left_account and leaves the stored company id alone, so the flag stays until a person resolves it. And no property is ever set to an empty value.

Why no empty values

HubSpot's documentation for the batch update says that provided values overwrite existing ones and that an empty string clears a property. In an enrichment script that turns a missing field in the API response into a deleted value in the CRM. Guard every assignment, as the script does with the title and the company id.

Let HubSpot act on the flag

Create a workflow that starts when kooperativa_status is left_account and creates a task for the contact owner. That uses a standard workflow action and not custom code, so it does not need the tier above. The task is the point of the whole routine: a champion or a buyer has moved, and somebody should look at the account.

Cost, limits and when not to use this

The bulk enrich call is part of the flat license, so a sweep adds no per-request fee. The live lookup is the only metered call, at $0.001 each, and it is worth paying for only on contacts attached to open deals. Every record carries a fetched_at, so you can see how old an answer is before you act on it.

If you need email addresses or phone numbers in HubSpot, use HubSpot's own enrichment or a contact data provider for those and keep this routine for employer and title. The same pattern works for Salesforce with its own API calls, but this article covers HubSpot only.

Frequently asked questions

How do I enrich HubSpot contacts with an API?

Read the contacts that carry a profile identifier with the CRM search endpoint, enrich them in batches of 100, and write the results to separate properties with the batch update endpoint. Guard every value so that nothing empty is ever written.

Do I need Operations Hub to enrich HubSpot from code?

Only if you run the code inside a workflow. HubSpot documents custom code actions under Operations Hub Professional or Enterprise. A script that runs outside HubSpot with a private app token does not use workflows.

Will the script overwrite what my reps typed?

Not if it writes to its own properties. Copy a verified value into a standard property only through a workflow or a person, and never from the script itself.

Does this add email addresses or phone numbers?

No. Kooperativa holds professional profile data and no contact details. Use HubSpot enrichment or a contact data provider for those.

Get started

Try Kooperativa

One API key. Person and company enrichment, structured search, and monitors under one flat license.

Keep reading

We use only cookies that are strictly necessary to run this site (staying signed in, and protecting forms from abuse). Our analytics tool doesn't use cookies or collect personal data. See our Privacy Policy for details.