{"record":{"id":"b14170e145b6844f","repo":"Budibase/budibase","slug":"invalid-custom-rest-template-id","errorCode":null,"errorMessage":"Invalid custom REST template ID","messagePattern":"Invalid custom REST template ID","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/restTemplate.ts","lineNumber":116,"sourceCode":"        fileExtension,\n        operationsCount: info.endpoints.length,\n      }),\n    }\n  } finally {\n    await unlink(uploadDetails.filepath).catch(() => {})\n  }\n}\n\nexport const update = async (\n  ctx: UserCtx<\n    UploadCustomRestTemplateRequest,\n    UpdateCustomRestTemplateResponse,\n    { restTemplateId: string }\n  >\n) => {\n  const { restTemplateId } = ctx.params\n  if (!isCustomRestTemplateId(restTemplateId)) {\n    throw new HTTPError(\"Invalid custom REST template ID\", 400)\n  }\n\n  const name = ctx.request.body.name\n  const description = ctx.request.body.description\n  if (typeof name !== \"string\" || !name.trim()) {\n    throw new HTTPError(\"Template name is required\", 400)\n  }\n  if (typeof description !== \"string\") {\n    throw new HTTPError(\"Template description is required\", 400)\n  }\n\n  ctx.body = {\n    template: await sdk.restTemplates.update({\n      restTemplateId,\n      name,\n      description,\n    }),\n  }","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/restTemplate.ts#L98-L134","documentation":"This 400 HTTPError is thrown by the REST template update controller when the restTemplateId URL parameter fails the isCustomRestTemplateId check from shared-core. Custom template IDs have a reserved format; arbitrary or system template IDs are rejected before any body validation occurs.","triggerScenarios":"PUT/PATCH to the update endpoint with a malformed ID, an ID belonging to a built-in (non-custom) template, or a truncated/random ID in the URL path.","commonSituations":"Hardcoded IDs copied from docs or other environments; calling update on a built-in template ID; stale IDs cached from a previous workspace.","solutions":["Fetch the template list first and use a restTemplateId returned by the fetch endpoint","Verify the ID matches the custom template ID format (isCustomRestTemplateId) before calling","Retry with the ID of an actual custom-uploaded template"],"exampleFix":"// before\nPUT /api/restTemplates/builtin_petstore  // not a custom ID\n// after\nconst templates = await fetch(\"/api/restTemplates\").then(r => r.json())\nconst id = templates.find(t => t.custom).id\nawait fetch(`/api/restTemplates/${id}`, { method: \"PUT\", ... })","handlingStrategy":"validation","validationCode":"import { isCustomRestTemplateId } from \"@budibase/shared-core\"\nif (!isCustomRestTemplateId(id)) {\n  throw new Error(\"Refusing to update: not a custom REST template ID\")\n}","typeGuard":"import { isCustomRestTemplateId } from \"@budibase/shared-core\"\n// use directly as the type guard before calling the API","tryCatchPattern":"try {\n  await updateTemplate(id, body)\n} catch (e) {\n  if (e?.status === 400 && /Invalid custom REST template ID/.test(e?.message)) {\n    // refresh template list and pick a valid custom ID\n  } else throw e\n}","preventionTips":["Only use IDs returned by the custom templates fetch endpoint","Never hardcode template IDs across environments","Check the template's custom flag before attempting update"],"tags":["validation","http-400","rest-template","invalid-identifier"],"backgroundTag":"invalid-resource-id","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}