Nightly HubSpot to OneSignal push audience tag sync

By General Input

Every night we copy the customer details that matter onto your push audience, so campaign targeting always matches your CRM instead of stale tags.

Integrations

  • OneSignal
  • HubSpot
  • Slack

Type

Deterministic Code

Categories

  • Marketing
  • Operations

Every night at 2am, keep my OneSignal audience in sync with HubSpot so the marketing team can target push campaigns using current CRM data instead of stale tags. Use a cron trigger. Every step is a fixed field to field mapping over structured records with no judgement calls, so build this as a code workflow.

Start by pulling contacts from HubSpot with the List Contacts operation. Request only the properties that matter for targeting: lifecycle stage, plan or tier, contact owner, last activity date, and the property that stores the person's OneSignal external user id. List Contacts is paginated, so page through every result and keep going until HubSpot stops returning a next page cursor. Do not assume the whole audience fits in one page.

For every contact that carries an external user id, write those values onto the matching OneSignal user with the Edit Tags by External User ID operation. Each HubSpot property maps one to one onto a named OneSignal tag: lifecycle stage to lifecycle_stage, plan or tier to plan, contact owner to owner, and last activity date to last_activity_date. Keep the tag names stable and predictable, because the marketing team's segments are built on top of them.

Two rules drive correctness. First, skip any contact with no external user id, since there is no OneSignal user to write to, and count it as skipped. Second, when a HubSpot property is blank, still send the matching tag with an empty string rather than omitting it. On this operation an empty string deletes the tag, and that is what makes the clean up half of this sync work: someone who drops out of a plan or goes quiet stops matching that segment on the very next run, so nobody is left sitting in a segment they no longer belong to.

Pace the writes, because a nightly full sync over a large contact list will otherwise trip OneSignal's limits. User and subscription writes are capped at 1,000 per second per app, and separately at 1 request per second for any individual user or subscription, so batch the updates and spread them out instead of firing the entire contact list at once. If OneSignal returns a 429, read the Retry-After header, wait that many seconds, then retry with exponential backoff. Treat 400, 401 and 403 as permanent failures for that contact: do not retry them, record the contact as errored, and continue, so one bad record never halts the run.

Finish by posting a one line summary to Slack with the Send a Message operation, reporting how many users were updated, how many were skipped for having no external user id, and how many errored. Send it to the marketing operations channel.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentWin back LiveChat visitors whose chats went unansweredTurn Mailjet email clicks into ranked HubSpot follow-upsiMessage campaign console with pre-flight checks and delivery boardChat quality review board for LiveChat support leadsA searchable RFP answer library your bid team drafts fromSee which target accounts just started advertising on LinkedInAccount health board that puts product usage next to your CRMLook up a customer's full chat history mid conversationLusha prospecting workbench with credit-safe reveals