automation // REST APILAB
OAuth Token Cache Pattern
Reuse Marketing Cloud access tokens instead of creating a new token for every API request.
apioauthtokencache
Trust & provenanceLAB
Evidence tierLABOfficial sources1Other sources0Last verified2026-10-05
Evidence tier describes my hands-on relationship with the content. Official sources describe platform contracts/documentation. Production observations should not automatically be treated as official limits.
Building an external integration, n8n custom flow or service that calls SFMC repeatedly.
async function getToken() {
if (cache.token && Date.now() < cache.expiresAt - 60_000) {
return cache.token;
}
const auth = await requestNewToken();
cache.token = auth.access_token;
cache.expiresAt = Date.now() + (auth.expires_in * 1000);
return cache.token;
}Salesforce recommends avoiding frequent token creation and specifically advises not requesting more than one access token every 20 minutes.
Keep client_secret on the server/secure credential store.
Do not copy this in-browser; it is service-side pseudocode.