{"record":{"id":"54656f0b3ba5c48e","repo":"twentyhq/twenty","slug":"missing-api-url-set-the-default-api-url-name","errorCode":null,"errorMessage":"Missing API url. Set the `${DEFAULT_API_URL_NAME}` environment variable or pass `baseUrl` to `RestApiClient`.","messagePattern":"Missing API url\\. Set the `(.+?)` environment variable or pass `baseUrl` to `RestApiClient`\\.","errorType":"exception","errorClass":"RestApiClientError","httpStatus":null,"severity":"critical","filePath":"packages/twenty-client-sdk/src/rest/index.ts","lineNumber":164,"sourceCode":"\n  patch<TResponse = unknown>(\n    path: string,\n    body?: unknown,\n    options?: RestApiRequestOptions,\n  ) {\n    return this.execute<TResponse>('PATCH', path, body, options);\n  }\n\n  delete<TResponse = unknown>(path: string, options?: RestApiRequestOptions) {\n    return this.execute<TResponse>('DELETE', path, undefined, options);\n  }\n\n  private resolveBaseUrl(): string {\n    const baseUrl =\n      this.baseUrl ?? getProcessEnvironment()[DEFAULT_API_URL_NAME];\n\n    if (!isDefined(baseUrl) || baseUrl.trim().length === 0) {\n      throw new RestApiClientError(\n        `Missing API url. Set the \\`${DEFAULT_API_URL_NAME}\\` environment variable or pass \\`baseUrl\\` to \\`RestApiClient\\`.`,\n      );\n    }\n\n    return baseUrl.replace(/\\/+$/, '');\n  }\n\n  private resolveFunctionsBaseUrl(): string | undefined {\n    const functionsBaseUrl =\n      getProcessEnvironment()[DEFAULT_FUNCTIONS_URL_NAME];\n\n    if (!isDefined(functionsBaseUrl) || functionsBaseUrl.trim().length === 0) {\n      return undefined;\n    }\n\n    return functionsBaseUrl.trim().replace(/\\/+$/, '');\n  }\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-client-sdk/src/rest/index.ts#L146-L182","documentation":"Thrown by RestApiClient.resolveBaseUrl (rest/index.ts:163-167) as a RestApiClientError when neither `baseUrl` was passed to the constructor nor the `TWENTY_API_URL` environment variable (DEFAULT_API_URL_NAME) is defined/non-empty. It is the entrypoint guard for every REST request, so the first call fails fast.","triggerScenarios":"Constructing `new RestApiClient()` without a baseUrl and calling any method (get/post/put/patch/delete/request) without TWENTY_API_URL in the environment. resolveBaseUrl runs inside resolveTarget on every request.","commonSituations":"Forgot to set TWENTY_API_URL in .env; SSR/build environment missing the variable; typo in the env var name; loading the client before dotenv.config() ran; passing an empty/whitespace string as baseUrl.","solutions":["Set the TWENTY_API_URL environment variable to your Twenty instance (e.g. https://app.twenty.com).","Or pass `baseUrl` explicitly: `new RestApiClient({ baseUrl: 'https://app.twenty.com' })`.","If using dotenv, ensure dotenv.config() runs before constructing the client.","Confirm the variable is exposed to the runtime (serverless/Container env)."],"exampleFix":"// before\nconst client = new RestApiClient();\n// after\nconst client = new RestApiClient({ baseUrl: process.env.TWENTY_API_URL! });","handlingStrategy":"validation","validationCode":"const baseUrl =\n  options?.baseUrl ?? process.env[DEFAULT_API_URL_NAME];\nif (!baseUrl || baseUrl.trim().length === 0) {\n  throw new Error('Configure TWENTY_API_URL before constructing RestApiClient');\n}\nconst client = new RestApiClient({ baseUrl });","typeGuard":"const hasBaseUrl = (opts?: RestApiClientOptions): boolean =>\n  isDefined(opts?.baseUrl) && opts.baseUrl.trim().length > 0;","tryCatchPattern":"try {\n  await client.get('/rest/objects/contact');\n} catch (err) {\n  if (err instanceof RestApiClientError && err.message.includes('Missing API url')) {\n    // set TWENTY_API_URL or pass baseUrl\n  }\n}","preventionTips":["Set TWENTY_API_URL in the deployment environment.","Pass baseUrl explicitly in code to remove ambient dependency.","Run dotenv.config() before instantiating the client.","Add a startup check that the env var is present."],"tags":["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"}