# Enrich ChartMogul customers when a HubSpot deal closes

> When a deal is marked closed won in HubSpot, we tag the matching ChartMogul customer with the plan and source, and record the sale details.

- Workflow type: code
- Services: ChartMogul, HubSpot
- Categories: Sales, Finance
- Published: 2026-08-04

## What it does

- Watches your HubSpot pipeline and picks up every deal that moves into a closed won stage.
- Finds the matching customer in ChartMogul using the email address of the main contact on the deal.
- Tags that customer with the plan tier they bought and where the deal came from, so revenue can be sliced by both later.
- Records the deal owner, the deal value, the close date and the contract length on the customer record.

## What you'll need

- A HubSpot account with deals and contacts, where closed won deals have a contact with an email address on them.
- A ChartMogul account that already has your billing data flowing into it.
- Agreement on which HubSpot fields hold the plan tier, the acquisition source and the contract term.

## Prompt

Build a code workflow that mirrors the commercial context of every won sale from HubSpot onto the matching ChartMogul customer, so revenue reporting can be segmented by how the deal was actually sold. Use the HubSpot poll trigger "Deal Created, Updated, or Stage Changed" (event type deals_updated) so the workflow runs whenever a deal is created, edited, or moved between stages.

First, check the stage of the deal that fired the trigger. Only continue if the deal is in a closed won stage. The stage filter belongs inside the workflow, not in the trigger. If the deal is in any other stage, exit immediately without writing anything and without treating it as an error. If the trigger payload does not carry the full deal record, read it back with HubSpot Search Deals filtered on the deal id.

For a closed won deal, use HubSpot Search Contacts to find the primary contact associated with the deal and read their email address. That email is the join key between the two systems. If the deal has no associated contact with a usable email address, exit cleanly and say why.

Look the customer up with ChartMogul Search Customers by Email. Treat an empty result as a normal outcome rather than a failure: billing frequently starts days after a deal closes, so the customer may not exist in ChartMogul yet. In that case, log that no customer matched and finish successfully. The next time the deal is touched in HubSpot the workflow runs again, and by then the customer will usually exist.

When a customer does match, apply tags with ChartMogul Add Tags to Customers by Email. Tag the plan tier the deal was sold at, and the acquisition source (for example the deal's lead source or original channel). Tags are additive, so this must not disturb tags already on the customer.

Then write the structured fields with ChartMogul Add Custom Attributes to Customers by Email: deal owner as a String, deal amount as an Integer, close date as a Timestamp, and contract term as a String. Two details matter here. ChartMogul custom attribute types are capitalized exactly as String, Integer, Decimal, Timestamp and Boolean. And ChartMogul monetary amounts are integers in cents, so multiply the HubSpot deal amount by 100 and round to a whole number before sending it. Send the close date as an ISO 8601 timestamp.

Optionally call ChartMogul Retrieve a Customer's Tags and Attributes afterwards to confirm the write landed, and include the tags and attributes that were applied in the run output so each run is auditable. Keep the field mapping fixed and deterministic. There is no judgement to make at any step, so no model reasoning is needed.

## How to customize

- Change which pipeline stages count as a win, if your team uses custom stage names.
- Swap in different details to tag or record, such as region, industry or the partner who referred the deal.
- Adjust which contact on the deal is used for matching, for example the billing contact instead of the main one.

## FAQ

### What happens if the customer is not in ChartMogul yet?

Nothing breaks. Billing often starts days after a deal is signed, so if no customer matches the email address yet, the run simply ends without making changes. The next time that deal is edited in HubSpot it tries again, and by then the customer usually exists.

### Will this work on HubSpot Free?

Yes for the basics. Deals and contacts are available on every HubSpot tier including free. Some of the fields you might want to copy across, such as a custom contract term field, may need a paid tier depending on your plan.

### Does this change anything in HubSpot?

No. HubSpot is only read from. Every change this makes lands on the ChartMogul side, so your CRM records stay exactly as your reps left them.

### Will it overwrite tags I already added in ChartMogul?

No. Tags are added alongside whatever is already on the customer. The recorded fields like deal value and close date are refreshed with the latest information from HubSpot, so corrections made after the deal closes still flow through.

### How soon after a deal closes does the customer get updated?

Within a few minutes of the deal being saved in HubSpot. Because it also runs on edits, a later correction to the amount or the close date will update ChartMogul too.

Use this prompt in General Input: https://www.generalinput.com/prompts/enrich-chartmogul-customers-when-a-hubspot-deal-closes