Skip to Content
Docs are evolving — expect frequent updates.
Company ReportCompany Report

Getting an Analysis Report

Every project in Kruncher.ai comes with an array of analyses. Each analysis contains detailed reports on company performance and insights. To get the latest report you need to:

  1. Search for the company by name to get its project data
  2. Pick the latest analysis from the analyses array (sorted by createdAt)
  3. Fetch the full report using that analysisId

Step 1: Find the Company and Get the Latest Analysis ID

Search for the company by name using the Search Projects endpoint. The response includes an analyses array on each project. Sort by createdAt to pick the most recent one.

CODE
const API_KEY = "YOUR_API_KEY_HERE";
 
// Search for the company by name
const searchRes = await fetch(
  "https://api.kruncher.ai/api/integration/project/search?keywords=acme",
  { headers: { "Authorization": API_KEY } }
);
const { data } = await searchRes.json();
 
if (!data.results.length) {
  throw new Error("Company not found");
}
 
const project = data.results[0];
console.log("Found project:", project.id, project.name);

Now retrieve the full project details (including analyses) using Find Companies and pick the latest analysis:

CODE
// Get project details with analyses
const projectsRes = await fetch(
  `https://api.kruncher.ai/api/integration/projects?search=${encodeURIComponent(project.name)}`,
  { headers: { "Authorization": API_KEY, "Content-Type": "application/json" } }
);
const projects = await projectsRes.json();
const company = projects.data.find((p) => p.id === project.id);
 
// Pick the latest analysis by createdAt
const latestAnalysis = company.analyses
  .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))[0];
 
const analysisId = latestAnalysis.id;
console.log("Latest analysis:", analysisId, latestAnalysis.status);

Step 2: Fetch the Full Report

Once you have the analysisId, request the full company report:

CODE
GET https://api.kruncher.ai/api/integration/analysis/detail?analysisId=<analysisId>
CODE
const reportRes = await fetch(
  `https://api.kruncher.ai/api/integration/analysis/detail?analysisId=${analysisId}`,
  {
    headers: {
      "Authorization": API_KEY,
      "Content-Type": "application/json"
    }
  }
);
const report = await reportRes.json();
console.log("Full Company Report:", report);

Full Example

Here’s the complete flow in a single function (for cURL, run each step sequentially):

CODE
const API_KEY = "YOUR_API_KEY_HERE";
const BASE_URL = "https://api.kruncher.ai/api";
 
async function getLatestReport(companyName) {
  // 1. Search for the company
  const searchRes = await fetch(
    `${BASE_URL}/integration/project/search?keywords=${encodeURIComponent(companyName)}`,
    { headers: { "Authorization": API_KEY } }
  );
  const searchData = await searchRes.json();
 
  if (!searchData.data.results.length) {
    throw new Error(`No company found for "${companyName}"`);
  }
 
  const projectId = searchData.data.results[0].id;
 
  // 2. Get project details with analyses
  const projectsRes = await fetch(
    `${BASE_URL}/integration/projects?search=${encodeURIComponent(companyName)}`,
    { headers: { "Authorization": API_KEY, "Content-Type": "application/json" } }
  );
  const projects = await projectsRes.json();
  const company = projects.data.find((p) => p.id === projectId);
 
  if (!company?.analyses?.length) {
    throw new Error("No analyses found for this company");
  }
 
  // Pick the latest analysis
  const latest = company.analyses
    .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))[0];
 
  // 3. Fetch the full report
  const reportRes = await fetch(
    `${BASE_URL}/integration/analysis/detail?analysisId=${latest.id}`,
    { headers: { "Authorization": API_KEY, "Content-Type": "application/json" } }
  );
 
  return await reportRes.json();
}
 
// Usage
const report = await getLatestReport("Acme Corp");
console.log(report);

For more details on the search API, see Search Projects. For the full response field reference, see Find Companies.

Last updated on