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

  1. Pass --company-id <id> (or --company <prefix>) when using --target existing-company.
  2. If you do not have a company yet, use --target new-company instead, which uses /api/companies/import and does not need an id.
  3. When calling resolveCompanyImportApiPath programmatically, guarantee input.companyId is a non-empty trimmed string before setting targetMode to 'existing_company'.
  4. 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

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


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/f1487ac85f990ecc. Report an issue: GitHub.