Skip to Content
Docs are evolving — expect frequent updates.
CompanyTrigger Analysis

Trigger Analysis for an Existing Company

This guide walks through the three steps to trigger a new analysis on a company that already exists in your portfolio:

  1. Find the company to get its projectId
  2. Create a new analysis for that project
  3. Upload files to the analysis (optional)

Step 1: Find the Company

Use the search endpoint to look up the company by name.

CODE
const API_KEY = "YOUR_API_KEY_HERE";
 
const response = await fetch(
  "https://api.kruncher.ai/api/integration/project/search?keywords=acme",
  {
    headers: { "Authorization": API_KEY }
  }
);
 
const { data } = await response.json();
const project = data.results[0];
console.log(project.id, project.name);

For full search options (pagination, status filtering, sorting), see Search Projects.

Step 2: Create a New Analysis

Pass the projectId to create a fresh analysis.

CODE
const analysisResponse = await fetch(
  "https://api.kruncher.ai/api/integration/analysis/company",
  {
    method: "POST",
    headers: {
      "Authorization": API_KEY,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ projectId: project.id })
  }
);
 
const { analysisId } = await analysisResponse.json();
console.log("Analysis ID:", analysisId);

For advanced options like polling for completion and error handling, see Create Analysis.

Step 3: Upload Files (Optional)

Attach documents to the analysis for deeper insights. Skip this step if you only need a website-based analysis.

CODE
const FormData = require("form-data");
const fs = require("fs");
 
const form = new FormData();
form.append("files", fs.createReadStream("pitch-deck.pdf"));
form.append("files", fs.createReadStream("financials.xlsx"));
 
await fetch("https://api.kruncher.ai/api/integrationfiles/upload", {
  method: "POST",
  headers: {
    "Authorization": API_KEY,
    "analysisid": analysisId,
    ...form.getHeaders()
  },
  body: form
});

For supported file formats and error handling, see Upload Files.

Full Example

Putting it all together:

CODE
const FormData = require("form-data");
const fs = require("fs");
 
const API_KEY = "YOUR_API_KEY_HERE";
const BASE_URL = "https://api.kruncher.ai/api";
 
async function triggerAnalysis(companyName, filePaths = []) {
  // 1. Find the company
  const searchRes = await fetch(
    `${BASE_URL}/integration/project/search?keywords=${encodeURIComponent(companyName)}`,
    { headers: { "Authorization": API_KEY } }
  );
  const { data } = await searchRes.json();
 
  if (!data.results.length) {
    throw new Error(`No company found for "${companyName}"`);
  }
 
  const projectId = data.results[0].id;
 
  // 2. Create analysis
  const analysisRes = await fetch(`${BASE_URL}/integration/analysis/company`, {
    method: "POST",
    headers: {
      "Authorization": API_KEY,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ projectId })
  });
  const { analysisId } = await analysisRes.json();
 
  // 3. Upload files (optional)
  if (filePaths.length > 0) {
    const form = new FormData();
    filePaths.forEach((fp) => form.append("files", fs.createReadStream(fp)));
 
    await fetch(`${BASE_URL}/integrationfiles/upload`, {
      method: "POST",
      headers: {
        "Authorization": API_KEY,
        "analysisid": analysisId,
        ...form.getHeaders()
      },
      body: form
    });
  }
 
  return { projectId, analysisId };
}
 
// Usage
const result = await triggerAnalysis("Acme Corp", ["pitch-deck.pdf"]);
console.log(result);
Last updated on