{"record":{"id":"e4dc24f6d2c7c038","repo":"twentyhq/twenty","slug":"caller-requires-the-app-runtime-env-vars-de","errorCode":null,"errorMessage":"${caller}() requires the app runtime env vars ${DEFAULT_API_URL_NAME} and ${DEFAULT_APP_ACCESS_TOKEN_NAME}.","messagePattern":"(.+?)\\(\\) requires the app runtime env vars (.+?) and (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/twenty-sdk/src/sdk/logic-function/utils/post-graphql-request.util.ts","lineNumber":19,"sourceCode":"import {\n  DEFAULT_API_URL_NAME,\n  DEFAULT_APP_ACCESS_TOKEN_NAME,\n} from 'twenty-shared/application';\n\nexport const postGraphqlRequest = async <TVariables, TData>({\n  query,\n  variables,\n  caller,\n}: {\n  query: string;\n  variables: TVariables;\n  caller: string;\n}): Promise<TData> => {\n  const apiUrl = process.env[DEFAULT_API_URL_NAME];\n  const accessToken = process.env[DEFAULT_APP_ACCESS_TOKEN_NAME];\n\n  if (!apiUrl || !accessToken) {\n    throw new Error(\n      `${caller}() requires the app runtime env vars ` +\n        `${DEFAULT_API_URL_NAME} and ${DEFAULT_APP_ACCESS_TOKEN_NAME}.`,\n    );\n  }\n\n  const response = await fetch(`${apiUrl}/metadata`, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application/json',\n      Authorization: `Bearer ${accessToken}`,\n    },\n    body: JSON.stringify({ query, variables }),\n  });\n\n  if (!response.ok) {\n    throw new Error(\n      `${caller}() failed: HTTP ${response.status} ${response.statusText}`,\n    );","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-sdk/src/sdk/logic-function/utils/post-graphql-request.util.ts#L1-L37","documentation":"Thrown by postGraphqlRequest (the core SDK GraphQL transport) when either TWENTY_API_URL or TWENTY_APP_ACCESS_TOKEN environment variables is missing or empty. These two env vars are the minimum runtime configuration for any SDK logic function that calls the Twenty metadata API. Without them, the function cannot construct a valid request URL or Authorization header.","triggerScenarios":"Calling any SDK logic function (getConnection, listConnections, etc.) without TWENTY_API_URL or TWENTY_APP_ACCESS_TOKEN set in process.env. The function checks both vars and throws before making any network request if either is absent.","commonSituations":"Running SDK logic functions in a local dev environment without loading .env. Deploying the app without setting the required environment variables. The env var names were changed or misconfigured. Using a different env var name by mistake (e.g. TWENTY_API_URL_V2 instead of TWENTY_API_URL).","solutions":["Set TWENTY_API_URL to your Twenty instance URL (e.g. https://api.twenty.com).","Set TWENTY_APP_ACCESS_TOKEN to a valid app access token obtained via the SDK CLI auth flow.","Ensure your environment loader (dotenv, etc.) runs before any SDK logic function is called.","Verify the variable names exactly match TWENTY_API_URL and TWENTY_APP_ACCESS_TOKEN."],"exampleFix":"// before — env vars not set\nimport { getConnection } from 'twenty-sdk';\nconst conn = await getConnection('conn-123');\n\n// after — ensure env vars are loaded\nimport 'dotenv/config'; // or set them in your deployment environment\n// process.env.TWENTY_API_URL = 'https://api.twenty.com'\n// process.env.TWENTY_APP_ACCESS_TOKEN = '...'\nconst conn = await getConnection('conn-123');","handlingStrategy":"validation","validationCode":"const validateSdkEnv = (): void => {\n  if (!process.env.TWENTY_API_URL || !process.env.TWENTY_APP_ACCESS_TOKEN) {\n    throw new Error(\n      'Missing env vars. Set TWENTY_API_URL and TWENTY_APP_ACCESS_TOKEN before calling SDK functions.',\n    );\n  }\n};\n\nvalidateSdkEnv();","typeGuard":"const hasSdkEnvVars = (): boolean => {\n  const url = process.env.TWENTY_API_URL;\n  const token = process.env.TWENTY_APP_ACCESS_TOKEN;\n  return typeof url === 'string' && url.length > 0 &&\n    typeof token === 'string' && token.length > 0;\n};","tryCatchPattern":"try {\n  const conn = await getConnection(id);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('requires the app runtime env vars')) {\n    console.error('Set TWENTY_API_URL and TWENTY_APP_ACCESS_TOKEN in your environment.');\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Load environment variables (dotenv) before any SDK logic function call.","Add a startup validation check for required env vars in your app's bootstrap.","Document TWENTY_API_URL and TWENTY_APP_ACCESS_TOKEN in your project's .env.example."],"tags":["sdk","environment","configuration","authentication"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}