Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Covers production HubSpot API auth: token caching/refresh, private app rotation, scope drift, rate-limit backoff, multi-portal routing.
Use this skill ↓57% 87%+30 ptsof test cases passed
Passed 20 of 23 test cases with the skill, and 13 of 23 without it.
HubSpot access tokens return an `expires_in` value of 1800 seconds. When caching this token in memory in a Node.js service, what exact time threshold or formula should be used to trigger a refresh before the token becomes invalid?
The refresh time threshold is set to 80% of the total token TTL.
3 of 3 safety checks passed
Authenticate a service to HubSpot and operate the auth layer in production. This is not a setup walkthrough — it is the auth code your integration runs at 3am when an OAuth token expires mid-batch, when a portal admin removes a scope, when an agency credential router sends a request to the wrong portal, and when on-call needs to rotate a leaked private-app token without dropping in-flight requests.
The six production failures this skill prevents:
403. Retrying does not help.pat-na1-* private-app tokens are wide-scope and not auto-expiring. A single leaked commit exposes the entire portal.HUBSPOT_ACCESS_TOKEN. Requests sent to the wrong portal silently operate on the wrong data.Build in this order. Each section neutralizes one production failure mode.
Reactive refresh on 401 is wrong. It doubles latency on the failing request and creates a thundering herd when all concurrent requests notice expiry at the same millisecond. Cache the token in-process and refresh proactively at 80% of TTL, behind a single-flight gate so concurrent callers serialize on one refresh.
This pattern applies to OAuth access tokens only — private-app tokens do not expire.
type Cached = { value: string; expiresAt: number };
let cached: Cached | null = null;
let inflight: Promise<string> | null = null;
export async function getToken(): Promise<string> {
// Refresh at 80% of TTL (1800s → refresh at 1440s elapsed, i.e. 360s before expiry)
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.