paperclipai/paperclip · error · Error
Existing-company imports require a companyId to resolve the
Error message
Existing-company imports require a companyId to resolve the API route.
What it means
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.
Source
Thrown at cli/src/commands/client/company.ts:781
function printCompanyImportView(title: string, body: string, opts?: { interactive?: boolean }): void {
if (opts?.interactive) {
p.note(body, title);
return;
}
console.log(pc.bold(title));
console.log(body);
}
export function resolveCompanyImportApiPath(input: {
dryRun: boolean;
targetMode: "new_company" | "existing_company";
companyId?: string | null;
}): string {
if (input.targetMode === "existing_company") {
const companyId = input.companyId?.trim();
if (!companyId) {
throw new Error("Existing-company imports require a companyId to resolve the API route.");
}
return input.dryRun
? apiPath`/api/companies/${companyId}/imports/preview`
: apiPath`/api/companies/${companyId}/imports/apply`;
}
return input.dryRun ? "/api/companies/import/preview" : "/api/companies/import";
}
export function buildCompanyDashboardUrl(apiBase: string, issuePrefix: string): string {
const url = new URL(apiBase);
const normalizedPrefix = issuePrefix.trim().replace(/^\/+|\/+$/g, "");
url.pathname = `${url.pathname.replace(/\/+$/, "")}/${normalizedPrefix}/dashboard`;
url.search = "";
url.hash = "";
return url.toString();
}
View on GitHub (pinned to 67001ec6eb)
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.
Example fix
// before
resolveCompanyImportApiPath({ dryRun: true, targetMode: "existing_company", companyId: "" });
// after
resolveCompanyImportApiPath({ dryRun: true, targetMode: "existing_company", companyId: "cmp_abc123" }); Defensive patterns
Strategy: validation
Validate before calling
function validateExistingCompanyImportInput(input: {
targetMode: "new_company" | "existing_company";\n companyId?: string | null;
}): void {
if (input.targetMode === "existing_company") {
const id = input.companyId?.trim();
if (!id) {
throw new Error("Pass a non-empty companyId for existing-company import.");
}
}
}
// call before resolveCompanyImportApiPath
validateExistingCompanyImportInput({ targetMode, companyId }); Type guard
function isExistingCompanyImportReady(input: {
targetMode: string;
companyId?: string | null;
}): boolean {
return (
input.targetMode === "existing_company" &&
typeof input.companyId === "string" &&
input.companyId.trim().length > 0
);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Applying a company import with --json requires --yes. Use --
- Applying a company import from a non-interactive terminal re
- GitHub source must be a GitHub or GitHub Enterprise URL, or
- Invalid GitHub URL.
- Company selector is required.
AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12).
Data as JSON: /api/errors/f1487ac85f990ecc.
Report an issue: GitHub.