{"record":{"id":"a78483c2aaeda5b6","repo":"Budibase/budibase","slug":"invalid-custom-rest-template","errorCode":null,"errorMessage":"Invalid custom REST template","messagePattern":"Invalid custom REST template","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/settings/pages/connections/_components/createImportedRestConnection.ts","lineNumber":18,"sourceCode":"import type { RestTemplate, UIIntegration } from \"@budibase/types\"\nimport { API } from \"@/api\"\nimport { configFromIntegration } from \"@/stores/selectors\"\nimport { datasources } from \"@/stores/builder/datasources\"\nimport { getRestTemplateImportInfoRequest } from \"@/helpers/restTemplates\"\n\nexport const createImportedRestConnection = async ({\n  template,\n  integration,\n  projectIds,\n}: {\n  template: RestTemplate\n  integration: UIIntegration\n  projectIds?: string[]\n}) => {\n  const request = getRestTemplateImportInfoRequest(undefined, template.id)\n  if (!request) {\n    throw new Error(\"Invalid custom REST template\")\n  }\n\n  const info = await API.getImportInfo(request)\n  const config = {\n    ...configFromIntegration(integration),\n    url: info.servers?.[0]?.url ?? info.url ?? \"\",\n    authConfigs: [],\n    staticVariables: info.staticVariables || {},\n    defaultHeaders: {},\n    defaultQueryParameters: {},\n    rejectUnauthorized: true,\n    downloadImages: true,\n  }\n\n  return await datasources.create({\n    integration,\n    config,\n    name: template.name,","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/settings/pages/connections/_components/createImportedRestConnection.ts#L1-L36","documentation":"createImportedRestConnection resolves import metadata for a REST template via getRestTemplateImportInfoRequest. That helper returns null for custom REST templates it cannot translate into a valid import request (e.g. an id that is not a known preset). When the request is null the function throws 'Invalid custom REST template' instead of calling the API with a malformed request.","triggerScenarios":"Calling createImportedRestConnection with a RestTemplate whose id is not a recognized preset template — e.g. a user-defined/custom REST template passed where the function expects a built-in template id, with no templateId derived from it.","commonSituations":"Passing a custom REST connection object instead of a preset template; template ids from older versions or other environments not recognized; automation/scripts replaying saved template configs whose ids no longer exist.","solutions":["Use one of the supported preset REST template ids (built-in templates) for this import path.","For custom REST APIs, create the datasource directly with its URL/config instead of going through template import.","Verify template.id is correct and corresponds to a template available in the current environment."],"exampleFix":"// before\nawait createImportedRestConnection({ template: { id: \"my-custom-api\" }, integration })\n// after\nawait API.createDatasource({ datasource: { datasourceType: \"REST\", name: \"my-api\", config: { url: \"https://api.example.com\" } } })","handlingStrategy":"validation","validationCode":"const request = getRestTemplateImportInfoRequest(undefined, template.id)\nif (!request) {\n  // route to manual REST datasource creation instead of throwing\n  return createManualRestDatasource(integration, template)\n}","typeGuard":"const isPresetTemplate = (t: RestTemplate): t is RestTemplate & { id: PresetRestTemplateId } =>\n  PRESET_REST_TEMPLATE_IDS.includes(t.id as PresetRestTemplateId)","tryCatchPattern":"try {\n  return await createImportedRestConnection({ template, integration })\n} catch (e) {\n  if (e.message === \"Invalid custom REST template\") {\n    return createManualRestDatasource(integration, template)\n  }\n  throw e\n}","preventionTips":["Only pass built-in/preset template ids to template-based import helpers.","Use direct datasource creation with explicit URL/config for custom REST APIs.","Validate template.id against the current list of available templates before calling."],"tags":["rest","templates","validation","builder"],"backgroundTag":"invalid-template-id","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}