# Validate before you send, a .NET 8 job for bulk HubSpot upserts

> Source: <https://dev.to/tayyab_hafiz_dev_0/validate-before-you-send-a-net-8-job-for-bulk-hubspot-upserts-g7e>
> Published: 2026-11-25 16:00:09+00:00

**Recommendation:** Validate each record against the portal's fetched property definitions and share a single rate limiter across all tasks; split rejected batches until the bad row is isolated.
More in the playbook "Running AI in production": <https://wpnews.pro/playbooks/production-ops>

This article was drafted with AI help and reviewed by the author.

Bulk loads into HubSpot tend to fail in two boring ways.

The first is bad values. A dropdown gets "Software" when the option's internal value is something else. A date arrives as "31/01/2020". A column maps to a property that doesn't exist, or to one HubSpot won't let you write. One of those in a batch of 100 can get the whole request rejected.

The second is rate limits. Someone adds parallelism to speed the load up, and the job spends the night collecting 429s.

This post describes a small .NET 8 worker that handles both. It validates each record against the property definitions HubSpot returns for your portal, so most bad values never cost an API call. It funnels every request through one shared rate limiter. When HubSpot still rejects a batch, it splits the batch until the bad row is isolated. It gets the HubSpot token from Key Vault with a managed identity and runs as a job, not a service.

The validation, throttling and batch-splitting behavior described below was exercised earlier with a fake HTTP handler that returned property definitions, a 429 and a 400. Nothing was run against a real HubSpot portal or a live Key Vault.

Recheck these before you rely on them.

The mapping sheet says which source column goes to which HubSpot property. It doesn't know which dropdown options exist in this portal today, or which properties are read-only. HubSpot does. So the job asks once at startup, then checks every record locally before any write.

What it catches:

Blank values are dropped. Sending an empty string would wipe whatever HubSpot already holds, and in a source export a blank usually just means unknown.

A record that fails validation is rejected locally with every reason listed. Nobody has to dig through a 400 response to find out which column was wrong.

**A worked example.** These are made-up values, used only to show the checks. The job has just loaded the contact property definitions for the portal. Among them:

Now take four source rows.

Row 1, contact C-501. Industry is "Software". The validator finds a case-insensitive match and will send "software", which is the spelling HubSpot expects. The row is accepted.

Row 2, contact C-502. Industry is "Gaming". There is no such option. The validator rejects the row locally, with a reason that "Gaming" is not a valid industry option. This never becomes an API call.

Row 3, deal D-40. Close date is "31/01/2020". That is not an ISO 8601 complete date. The validator rejects the row and asks for a value in the form 2020-01-31. A later correction to 2020-01-31 is accepted.

Row 4, contact C-503. The mapping tries to write the calculated score, and also has a blank phone number and Interests set to webinar and newsletter. The score is dropped as a read-only property, with a reason attached, so the whole row is rejected until the mapping stops targeting it. Phone is simply omitted, because a blank should not clear a value HubSpot already has. If the score were removed from the mapping, the interests list would be sent as HubSpot's two canonical options, with no separator in front, so a rerun replaces the list instead of appending to it.

Each rejected row can carry more than one reason. If C-503 also had a typo in a property name, both reasons would appear together.

The important design choice is that the limiter is a singleton. HubSpot's burst limit applies per app. If each HTTP client or each parallel task had its own limiter, they'd each think they had the full budget. One sliding-window limiter, registered once and shared by the handler, makes parallelism safe. Extra tasks just queue for permits.

The default of 150 permits in a 10-second window leaves room under a 190 burst limit for retries and for anything else using the same app. On a Free or Starter portal, set it below 100.

The handler then treats the two kinds of 429 differently:

Server-error responses get exponential backoff. Other 4xx responses go straight back to the caller, because retrying a validation error won't change it.

**A worked example.** The job is mid-way through contacts when two things happen in the same hour.

First, a burst 429 arrives. The handler waits 10 seconds and resends the same batch. The second attempt succeeds, and the job continues.

Later, a 429 arrives with the policy named DAILY. The worker logs that the daily allowance is gone and stops itself. Contacts that were not yet sent stay pending in the store. The next scheduled run, after the HubSpot account clock rolls over to the next day, picks them up. The job does not sit in a retry loop overnight.

Once a record passes local validation, it goes into a batch of up to 100. Each input is keyed on the unique "legacy*crm*id" property. That property needs to be marked unique when you create it. The object write trace ID on each input is the same legacy ID.

Three things worth pointing out.

**Results are matched by trace ID.** The result for that record carries the trace ID back, so there's no reliance on result order. Any input without a matching result is marked rejected with the batch's error messages.

**A 400 on a multi-record batch triggers a split.** The batch is halved and each half is sent again, recursively, down to single records. With pre-validation doing most of the work, this should be rare. When it happens, the good records still go through, and the one HubSpot dislikes ends up rejected on its own with HubSpot's message attached. A batch of 100 with one bad record costs about 14 extra calls, not 100.

**The unique legacy ID is why a second run is harmless.** A record sent twice is updated, not duplicated.

**A worked example of a split.** A batch of 100 contacts is sent. Local validation passed, but HubSpot now rejects the whole request with a 400. Hidden in the middle is C-577, whose country value was added as a dropdown option in the mapping sheet and not yet created in the portal.

The job splits the 100 into two groups of 50 and sends each group. The first 50 succeed. The second 50 fail again. That half is split into 25 and 25, then again, until C-577 is sent on its own and fails with HubSpot's message. Every other contact in the original batch is upserted. C-577 is stored as rejected, with that message, so a person can create the option and queue the one row again.

If the 400 had named C-577 clearly, the split would still be worth doing, because a single rejected batch must not block the 99 good rows.

The worker is a hosted background service. On start it:

Notes on the host:

A migration is a batch job, so schedule it like one. On AKS with workload identity, a CronJob is a good fit. An Azure Container Apps job is equally good if you don't run a cluster.

A few settings matter more than the rest of the manifest:

**A worked example.** The job is scheduled every night at 01:00 in the HubSpot account's time zone. Monday's run is still going at 01:00 on Tuesday, because a large contact file took longer than expected. Because overlap is forbidden, Tuesday's run is skipped, and Monday's process keeps the only limiter. If overlap had been allowed, two workers would have issued requests against the same app budget and could have triggered burst 429s that neither of them caused on their own.

This covers the loading engine only. For everything around it, including deciding what moves, cleaning the data, designing properties and pipelines, import order and the validation sign-off before the old CRM goes read-only, there's a thorough [CRM-to-HubSpot migration playbook](https://octacer.com/playbooks/crm-migration-to-hubspot-playbook) worth reading first.
