{"record":{"id":"1353ba717bf73814","repo":"twentyhq/twenty","slug":"missing-application-access-token-set-the-defau","errorCode":null,"errorMessage":"Missing application access token. Set the `${DEFAULT_APP_ACCESS_TOKEN_NAME}` environment variable or pass `token` to `RestApiClient`.","messagePattern":"Missing application access token\\. Set the `(.+?)` environment variable or pass `token` to `RestApiClient`\\.","errorType":"exception","errorClass":"RestApiClientError","httpStatus":null,"severity":"critical","filePath":"packages/twenty-client-sdk/src/rest/index.ts","lineNumber":212,"sourceCode":"    };\n  }\n\n  private resolveToken(): string {\n    if (!isDefined(this.authorizationToken)) {\n      const processEnvironment = getProcessEnvironment();\n\n      this.authorizationToken =\n        this.token ??\n        processEnvironment[DEFAULT_APP_ACCESS_TOKEN_NAME] ??\n        processEnvironment[DEFAULT_API_KEY_NAME] ??\n        null;\n    }\n\n    if (\n      !isDefined(this.authorizationToken) ||\n      this.authorizationToken.length === 0\n    ) {\n      throw new RestApiClientError(\n        `Missing application access token. Set the \\`${DEFAULT_APP_ACCESS_TOKEN_NAME}\\` environment variable or pass \\`token\\` to \\`RestApiClient\\`.`,\n      );\n    }\n\n    return this.authorizationToken;\n  }\n\n  private async requestRefreshedAccessToken(): Promise<string | null> {\n    const refreshAccessTokenFunction = (\n      globalThis as {\n        frontComponentHostCommunicationApi?: {\n          requestAccessTokenRefresh?: () => Promise<string>;\n        };\n      }\n    ).frontComponentHostCommunicationApi?.requestAccessTokenRefresh;\n\n    if (typeof refreshAccessTokenFunction !== 'function') {\n      return null;","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-client-sdk/src/rest/index.ts#L194-L230","documentation":"Thrown by RestApiClient.resolveToken (rest/index.ts:208-215) as a RestApiClientError when no authorization source is available: no `token` in constructor options, no TWENTY_ACCESS_TOKEN env var, and no TWENTY_API_KEY env var. The client tries each in order and fails the request if all are missing/empty.","triggerScenarios":"Constructing `new RestApiClient({ baseUrl })` without a token and calling any REST method without TWENTY_ACCESS_TOKEN or TWENTY_API_KEY in the environment.","commonSituations":"Missing TWENTY_ACCESS_TOKEN env var in CI/serverless; token option omitted and env not loaded; whitespace-only token value; loading the client before dotenv.config(); forgetting to pass the token in front-component hosts that lack env access.","solutions":["Set TWENTY_ACCESS_TOKEN (or TWENTY_API_KEY) in the environment.","Or pass `token` explicitly: `new RestApiClient({ baseUrl, token })`.","Ensure the token is non-empty after trimming.","If running inside a Twenty front component, wire the host refresh API so the token is populated."],"exampleFix":"// before\nconst client = new RestApiClient({ baseUrl });\n// after\nconst client = new RestApiClient({ baseUrl, token: process.env.TWENTY_ACCESS_TOKEN! });","handlingStrategy":"validation","validationCode":"const token =\n  options?.token ??\n  process.env[DEFAULT_APP_ACCESS_TOKEN_NAME] ??\n  process.env[DEFAULT_API_KEY_NAME];\nif (!token || token.length === 0) {\n  throw new Error('Configure TWENTY_ACCESS_TOKEN or TWENTY_API_KEY');\n}\nconst client = new RestApiClient({ baseUrl, token });","typeGuard":"const hasToken = (opts?: RestApiClientOptions): boolean =>\n  isDefined(opts?.token) && opts.token.length > 0;","tryCatchPattern":"try {\n  await client.get('/rest/objects/contact');\n} catch (err) {\n  if (err instanceof RestApiClientError && err.message.includes('Missing application access token')) {\n    // provide a token via env or constructor\n  }\n}","preventionTips":["Pass token explicitly rather than relying on env.","Ensure TWENTY_ACCESS_TOKEN is in CI/serverless env.","Wire front-component host refresh API to keep tokens fresh.","Validate token presence at startup."],"tags":["authentication","configuration","environment","client-sdk","rest"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}