Budibase/budibase · error · HTTPError

Custom REST template not found

Error message

Custom REST template not found

What it means

A 404 HTTPError thrown by update (updateWithoutLock) when no custom REST template document exists for the given restTemplateId, or the doc exists without a _rev (making it un-updatable). The update is refused before any name validation or persistence.

Source

Thrown at packages/server/src/sdk/workspace/restTemplates.ts:181

export const create = async (params: CreateCustomRestTemplateParams) =>
  withCustomRestTemplateLock({
    resource: "workspace",
    task: () => createWithoutLock(params),
  })

const updateWithoutLock = async ({
  restTemplateId,
  name,
  description,
}: {
  restTemplateId: CustomRestTemplateId
  name: string
  description: string
}): Promise<RestTemplate> => {
  const db = context.getWorkspaceDB()
  const document = await db.tryGet<CustomRestTemplateDocument>(restTemplateId)
  if (!document?._rev) {
    throw new HTTPError("Custom REST template not found", 404)
  }

  const normalizedName = kebabCase(name)
  if (!normalizedName) {
    throw new HTTPError("Template name must contain letters or numbers", 400)
  }
  const duplicate = (await fetch()).find(
    template =>
      template.id !== restTemplateId &&
      kebabCase(template.name) === normalizedName
  )
  if (duplicate) {
    throw new HTTPError(
      `A custom REST template named "${name.trim()}" already exists`,
      409
    )
  }

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Re-fetch the template list and confirm the id still exists before updating
  2. Re-create the template if it was deleted, then apply the update to the new id
  3. Verify the id came from the same workspace/tenant context as the update call
  4. Refresh the client's template cache after any delete so stale ids aren't used

Example fix

// before
await restTemplates.update(restTemplateId, { name, description })
// after
const tpl = (await restTemplates.fetch()).find(t => t.id === restTemplateId)
if (!tpl) throw new Error(`Template ${restTemplateId} no longer exists`)
await restTemplates.update(restTemplateId, { name, description })
Defensive patterns

Strategy: validation

Validate before calling

const tpl = (await restTemplates.fetch()).find(t => t.id === restTemplateId)
if (!tpl) throw new Error(`Template ${restTemplateId} not found; cannot update`)

Type guard

function templateExists(t: RestTemplate | undefined): t is RestTemplate
  return !!t && typeof t.id === "string"

Try / catch

try {
  await restTemplates.update(restTemplateId, { name, description })
} catch (e) {
  if (e?.status === 404) {
    // refresh template list; recreate or inform the user
    return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling update with a restTemplateId that was deleted, never existed, belongs to another workspace, or references an orphaned doc lacking _rev; also after the template was removed by a concurrent request.

Common situations: Client cached a template list that is now stale; template id copy-pasted from a different environment/tenant; the template was deleted while an edit dialog was open; automation referencing a template by hard-coded id after cleanup.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/fa1a42c8ed54835b. Report an issue: GitHub.