{"record":{"id":"4c0a9cd98b22ee46","repo":"Budibase/budibase","slug":"project-package-doc-id-does-not-match-resourc","errorCode":null,"errorMessage":"Project package doc '${id}' does not match resource type '${importedDoc.resourceType}'.","messagePattern":"Project package doc '(.+?)' does not match resource type '(.+?)'\\.","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/projects/backups/imports.ts","lineNumber":351,"sourceCode":"  [ResourceType.AUTOMATION]: [prefixed(DocumentType.AUTOMATION)],\n  [ResourceType.WORKSPACE_APP]: [prefixed(DocumentType.WORKSPACE_APP)],\n  [ResourceType.SCREEN]: [prefixed(DocumentType.SCREEN)],\n}\n\nconst validateDocMatchesPath = (importedDoc: ImportedDoc) => {\n  const id = importedDoc.doc._id\n  if (!id) {\n    throw new HTTPError(\"Project package contains a doc without an id.\", 400)\n  }\n\n  const expectedFileName = `${id}.json`\n  if (basename(importedDoc.path) !== expectedFileName) {\n    throw new HTTPError(`Project package doc path does not match '${id}'.`, 400)\n  }\n\n  const validPrefixes = RESOURCE_ID_PREFIXES[importedDoc.resourceType]\n  if (!validPrefixes.some(prefix => id.startsWith(prefix))) {\n    throw new HTTPError(\n      `Project package doc '${id}' does not match resource type '${importedDoc.resourceType}'.`,\n      400\n    )\n  }\n}\n\nconst remapObjectKeys = <T>(\n  value: Record<string, T>,\n  idMap: Map<string, string>\n) => {\n  return Object.fromEntries(\n    Object.entries(value).map(([key, nestedValue]) => [\n      idMap.get(key) || key,\n      nestedValue,\n    ])\n  )\n}\n","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/projects/backups/imports.ts#L333-L369","documentation":"validateDocMatchesPath also checks that the doc `_id`'s prefix is valid for its declared resourceType, using RESOURCE_ID_PREFIXES (e.g. PROJECT ids use the `app_`-prefixed PROJECT doc prefix, SCREEN ids the screen prefix). A doc whose id prefix doesn't match its folder/resource type is rejected with this HTTPError (400).","triggerScenarios":"A doc under `documents/tables/` whose `_id` doesn't start with the table doc prefix (e.g. a screen id in the tables folder, or an id missing its type prefix entirely), or a resourceType folder that was renamed/moved causing ids to no longer align.","commonSituations":"Manually moving doc files between resource folders; hand-crafting ids without the correct `ta_`/`vi_`/`ta_doc`-style prefixes; package assembled from multiple exports with mixed id schemes; version changes in id prefix formats.","solutions":["Move the doc into the folder matching its id prefix (per RESOURCE_ID_PREFIXES in imports.ts), or correct the id/prefix.","Generate ids with the proper helper (e.g. Budibase's `generateID`/prefix utilities) instead of inventing ids by hand.","Re-export from a compatible Budibase version so prefixes and folders align.","Add a validation step: for each doc, assert id startsWith one of RESOURCE_ID_PREFIXES[resourceType] before packaging."],"exampleFix":"// before: documents/screens/screen_xy.json contains _id \"ta_abc123\"\n// after: move it to the tables folder (or fix the id)\nmv documents/screens/screen_xy.json documents/tables/ta_abc123.json","handlingStrategy":"validation","validationCode":"// mirror RESOURCE_ID_PREFIXES from imports.ts\nconst PREFIXES: Record<string, string[]> = {\n  app: [\"app_doc\"], // adjust to actual prefixes per resource type\n  table: [\"ta_doc\"],\n}\n\nfunction idMatchesResourceType(id: string, resourceType: string, prefixes: Record<string, string[]>): boolean {\n  return (prefixes[resourceType] ?? []).some(p => id.startsWith(p))\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.importProjectPackage(file)\n} catch (err) {\n  if (err?.status === 400 && err.message.includes(\"does not match resource type\")) {\n    // move the doc to the folder matching its id prefix, or fix the id prefix\n  } else throw err\n}","preventionTips":["Generate ids with Budibase's official id helpers (correct type prefixes) instead of inventing them","Never move doc files between resource-type folders without regenerating ids","Validate id prefix vs folder for every doc before packaging","Keep exporter and importer on compatible versions since prefix formats can change"],"tags":["http-400","import","id-prefix","resource-type"],"backgroundTag":"doc-resource-type-mismatch","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}