You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Write OAuth to environment variablesif(pm.response.code==200){constresponseJson=pm.response.json();constaccess_token=responseJson.access_token;pm.environment.set("__access_token",access_token)constexpires_in=responseJson.expires_in;constnow=Date.now()/1000;constexpires_at=now+expires_in-100;pm.environment.set("__expires_at",expires_at)console.log("writing token data to env variables complete!")}else{console.warn('unsucessful auth. wiping existing keys if any.')pm.environment.set("__access_token",'')pm.environment.set("__expires_at",'')}
Check if auth token is active
// Check if auth token is activeconstcurrentTimestamp=Date.now()/1000;constexpires_at=pm.environment.get("__expires_at")constaccess_token=pm.environment.get("__access_token")if(!expires_at||!access_token){thrownewError('No token available. Please generate new one.')}if(currentTimestamp>expires_at){thrownewError('Auth token has expired. Please generate new one.')}else{console.log(`Auth token is valid for ${getRemainingMinutes(expires_at)} minutes.`);}functiongetRemainingMinutes(expires_at){constcurrentTimestamp=Math.floor(Date.now()/1000);consttimeDiff=expires_at-currentTimestamp;constremainingMinutes=Math.max(0,Math.floor(timeDiff/60));returnremainingMinutes;}
Update variables in request
// Update variables in requestpm.variables.set("AccountNumber","1234")