{"record":{"id":"f1487ac85f990ecc","repo":"paperclipai/paperclip","slug":"existing-company-imports-require-a-companyid-to-re","errorCode":null,"errorMessage":"Existing-company imports require a companyId to resolve the API route.","messagePattern":"Existing-company imports require a companyId to resolve the API route\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/company.ts","lineNumber":781,"sourceCode":"\nfunction printCompanyImportView(title: string, body: string, opts?: { interactive?: boolean }): void {\n  if (opts?.interactive) {\n    p.note(body, title);\n    return;\n  }\n  console.log(pc.bold(title));\n  console.log(body);\n}\n\nexport function resolveCompanyImportApiPath(input: {\n  dryRun: boolean;\n  targetMode: \"new_company\" | \"existing_company\";\n  companyId?: string | null;\n}): string {\n  if (input.targetMode === \"existing_company\") {\n    const companyId = input.companyId?.trim();\n    if (!companyId) {\n      throw new Error(\"Existing-company imports require a companyId to resolve the API route.\");\n    }\n    return input.dryRun\n      ? apiPath`/api/companies/${companyId}/imports/preview`\n      : apiPath`/api/companies/${companyId}/imports/apply`;\n  }\n\n  return input.dryRun ? \"/api/companies/import/preview\" : \"/api/companies/import\";\n}\n\nexport function buildCompanyDashboardUrl(apiBase: string, issuePrefix: string): string {\n  const url = new URL(apiBase);\n  const normalizedPrefix = issuePrefix.trim().replace(/^\\/+|\\/+$/g, \"\");\n  url.pathname = `${url.pathname.replace(/\\/+$/, \"\")}/${normalizedPrefix}/dashboard`;\n  url.search = \"\";\n  url.hash = \"\";\n  return url.toString();\n}\n","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/company.ts#L763-L799","documentation":"Thrown by resolveCompanyImportApiPath when targetMode is 'existing_company' but companyId is missing or whitespace-only. The function cannot build the scoped import route /api/companies/:id/imports/{preview|apply} without it, because every company import API requires an explicit company id in the path.","triggerScenarios":"Calling the company import command with --target existing-company (or selecting existing-company mode interactively) while omitting --company-id, passing an empty string, or passing only whitespace. Also reached if a programmatic caller sets targetMode to 'existing_company' but leaves companyId null/undefined.","commonSituations":"A user runs 'paperclipai company import --target existing-company' and assumes the CLI picks the company from the configured default. Scripts that hard-code targetMode='existing_company' but forget to thread the resolved company id through. Migration from 'new_company' mode where companyId was not previously required.","solutions":["Pass --company-id <id> (or --company <prefix>) when using --target existing-company.","If you do not have a company yet, use --target new-company instead, which uses /api/companies/import and does not need an id.","When calling resolveCompanyImportApiPath programmatically, guarantee input.companyId is a non-empty trimmed string before setting targetMode to 'existing_company'.","List companies first with 'paperclipai company list' to copy the exact id."],"exampleFix":"// before\nresolveCompanyImportApiPath({ dryRun: true, targetMode: \"existing_company\", companyId: \"\" });\n// after\nresolveCompanyImportApiPath({ dryRun: true, targetMode: \"existing_company\", companyId: \"cmp_abc123\" });","handlingStrategy":"validation","validationCode":"function validateExistingCompanyImportInput(input: {\n  targetMode: \"new_company\" | \"existing_company\";\\n  companyId?: string | null;\n}): void {\n  if (input.targetMode === \"existing_company\") {\n    const id = input.companyId?.trim();\n    if (!id) {\n      throw new Error(\"Pass a non-empty companyId for existing-company import.\");\n    }\n  }\n}\n// call before resolveCompanyImportApiPath\nvalidateExistingCompanyImportInput({ targetMode, companyId });","typeGuard":"function isExistingCompanyImportReady(input: {\n  targetMode: string;\n  companyId?: string | null;\n}): boolean {\n  return (\n    input.targetMode === \"existing_company\" &&\n    typeof input.companyId === \"string\" &&\n    input.companyId.trim().length > 0\n  );\n}","tryCatchPattern":null,"preventionTips":["Resolve the company id from 'paperclipai company list' before constructing the import call.","Treat targetMode and companyId as a paired contract in CLI option parsing.","Default new users to targetMode 'new_company' to avoid needing an id."],"tags":["cli","validation","company-import","argument-error"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}