Skip to Content
Docs are evolving — expect frequent updates.
ConfigMappingGet Mapping

Get Mapping

Retrieve a specific mapping between a Kruncher entity and an external provider ID. Use this to verify mappings exist, get bidirectional ID conversions, or integrate with external systems.

Endpoints

Option 1: Get All Mappings (Client-side Filtering)

GET https://api.kruncher.ai/api/integration/map/all

Fetches all mappings. Filter results client-side for your specific lookup.

Option 2: Find by External ID (Server-side Query)

GET https://api.kruncher.ai/api/integration/map/externalid?externalId=<external-id>

Returns mapping for a specific external system ID. Direct server-side lookup.

Option 3: Find by Kruncher ID (Server-side Query)

GET https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=<kruncher-id>

Returns mapping for a specific Kruncher internal ID. Direct server-side lookup.

Recommendation: Use query parameter endpoints (Options 2 & 3) for single lookups. Use Option 1 with client-side filtering when you need to batch lookup multiple mappings or filter by provider.

Headers

HeaderRequiredDescription
AuthorizationYesYour API key (format: YOUR_API_KEY)
Content-TypeNoOptional application/json

Query Parameters

externalId Endpoint

ParameterRequiredDescription
externalIdYesThe external system ID to lookup

Example: /api/integration/map/externalid?externalId=affinity_org_456

kruncherId Endpoint

ParameterRequiredDescription
kruncherIdYesThe Kruncher internal ID to lookup

Example: /api/integration/map/kruncherid?kruncherId=proj_123

Use Cases

When to Get Mappings

  • Before Syncing: Verify mapping exists before syncing data
  • ID Conversion: Convert between Kruncher IDs and external IDs
  • Mapping Verification: Confirm mapping is active
  • Integration Checks: Ensure sync is configured
  • Dependency Lookup: Find related entities in external systems

Quick Start Examples

Get Mapping by External ID

CODE
curl -X GET "https://api.kruncher.ai/api/integration/map/externalid?externalId=affinity_org_456" \
  -H "Authorization: YOUR_API_KEY_HERE"

Response:

CODE
{
  "data": {
    "id": "mapping_abc123",
    "entityType": "company",
    "provider": "affinity",
    "kruncherId": "proj_123",
    "externalId": "affinity_org_456",
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T10:30:00Z"
  }
}

Get Mapping by Kruncher ID

CODE
curl -X GET "https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=proj_123" \
  -H "Authorization: YOUR_API_KEY_HERE"

Response:

CODE
{
  "data": {
    "id": "mapping_abc123",
    "entityType": "company",
    "provider": "affinity",
    "kruncherId": "proj_123",
    "externalId": "affinity_org_456",
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T10:30:00Z"
  }
}

Code Examples

JavaScript/TypeScript

CODE
const API_KEY = "YOUR_API_KEY_HERE";
const BASE_URL = "https://api.kruncher.ai/api";
 
async function getMappingByKruncherId(kruncherId) {
  const url = `${BASE_URL}/integration/map/kruncherid?kruncherId=${encodeURIComponent(kruncherId)}`;
  
  const response = await fetch(url, {
    headers: {
      "Authorization": `${API_KEY}`,
      "Content-Type": "application/json"
    }
  });
 
  if (!response.ok) {
    if (response.status === 404) {
      return null;
    }
    throw new Error(`Failed to fetch mapping: ${response.statusText}`);
  }
 
  const result = await response.json();
  return result.data || null;
}
 
// Usage
const mapping = await getMappingByKruncherId("proj_123");
 
if (mapping) {
  console.log("Mapping found:", mapping);
  console.log("Provider:", mapping.provider);
  console.log("External ID:", mapping.externalId);
  console.log("Created:", mapping.createdAt);
} else {
  console.log("No mapping found for this Kruncher ID");
}

Result: Direct server-side lookup by Kruncher ID. Faster for single lookups.

Python

CODE
import requests
from typing import Optional, Dict
 
API_KEY = "YOUR_API_KEY_HERE"
BASE_URL = "https://api.kruncher.ai/api"
 
def get_mapping_by_kruncher_id(kruncher_id: str) -> Optional[Dict]:
    """Get mapping by Kruncher ID using server-side lookup."""
    url = f"{BASE_URL}/integration/map/kruncherid"
    
    headers = {
        "Authorization": f"{API_KEY}",
        "Content-Type": "application/json"
    }
    
    params = {
        "kruncherId": kruncher_id
    }
    
    response = requests.get(url, headers=headers, params=params)
    
    if response.status_code == 404:
        return None
    
    response.raise_for_status()
    result = response.json()
    
    return result.get('data')
 
# Usage
mapping = get_mapping_by_kruncher_id("proj_123")
 
if mapping:
    print(f"Found mapping: {mapping}")
    print(f"Provider: {mapping['provider']}")
    print(f"External ID: {mapping['externalId']}")
    print(f"Created: {mapping['createdAt']}")
else:
    print("No mapping found for this Kruncher ID")

Result: Direct server-side lookup by Kruncher ID. Faster for single lookups.

cURL

CODE
# Find mapping by Kruncher ID (server-side)
curl -s -X GET "https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=proj_123" \
  -H "Authorization: YOUR_API_KEY_HERE" \
  | jq '.data'
 
# Pretty print the result
curl -s -X GET "https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=proj_123" \
  -H "Authorization: YOUR_API_KEY_HERE" \
  | jq '.data | {kruncherId, externalId, provider, createdAt}'

Result: Direct server-side lookup by Kruncher ID.

Response Structure

Mapping Object

CODE
{
  "id": "mapping_abc123",
  "entityType": "company",
  "provider": "affinity",
  "kruncherId": "proj_123",
  "externalId": "affinity_org_456",
  "createdAt": "2024-01-15T10:30:00Z",
  "updatedAt": "2024-01-15T10:30:00Z",
  "customerId": "customer_xyz789"
}

Response Fields

FieldTypeDescription
idstringUnique mapping identifier
entityTypestringType: person, company, or opportunity
providerstringExternal provider (affinity, attio, pipedrive, etc.)
kruncherIdstringKruncher internal ID
externalIdstringExternal system ID
createdAtstringISO 8601 timestamp when created
updatedAtstringISO 8601 timestamp when last updated
customerIdstringYour customer/account ID

Endpoint Comparison

Which Endpoint Should I Use?

Use CaseEndpointProsCons
Single lookup by Kruncher ID/map/kruncherid?kruncherId=...Fast, simple, server-sideOnly one ID per request
Single lookup by external ID/map/externalid?externalId=...Fast, simple, server-sideOnly one ID per request
Batch lookups (multiple IDs)/map/all + filterGet all at once, flexibleSlower, larger response
Filter by provider/map/all + filterProvider-specific resultsClient-side processing
Check mapping exists/map/kruncherid or /map/externalidQuick verificationNeed to handle 404
Get all mappings/map/allComplete datasetLargest response, slower

Decision Tree:

CODE
Do you need a single ID lookup?
├─ Yes, have Kruncher ID? → Use /map/kruncherid
├─ Yes, have external ID? → Use /map/externalid
└─ No, multiple IDs? → Use /map/all and filter

Performance Characteristics

EndpointRequest SizeResponse SizeLatencyBest For
/map/kruncheridSmallSmallFastSingle Kruncher lookups
/map/externalidSmallSmallFastSingle external lookups
/map/allSmallLargeMediumBatch operations, filtering

Common Patterns

Pattern 1: Before Syncing Data (Direct Lookup)

CODE
// Before updating external system - using direct server-side lookup
async function syncToAffinity(kruncherId, data) {
  const url = `https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=${kruncherId}`;
  
  const response = await fetch(url, {
    headers: {
      "Authorization": `YOUR_API_KEY`,
      "Content-Type": "application/json"
    }
  });
  
  if (!response.ok) {
    console.error("Not mapped to Affinity");
    return;
  }
  
  const result = await response.json();
  const mapping = result.data;
  
  // Sync using external ID
  await updateAffinity(mapping.externalId, data);
  console.log(`Synced to Affinity: ${mapping.externalId}`);
}

When to use: Single sync operations, quick verification before updates.

Pattern 2: Bidirectional ID Lookup (Query Endpoints)

CODE
import requests
 
API_KEY = "YOUR_API_KEY_HERE"
BASE_URL = "https://api.kruncher.ai/api"
 
def get_external_id(kruncher_id):
    """Get external ID from Kruncher ID."""
    url = f"{BASE_URL}/integration/map/kruncherid"
    response = requests.get(url, 
        params={"kruncherId": kruncher_id},
        headers={"Authorization": f"{API_KEY}"}
    )
    if response.status_code == 200:
        return response.json()['data']['externalId']
    return None
 
def get_kruncher_id(external_id):
    """Get Kruncher ID from external ID."""
    url = f"{BASE_URL}/integration/map/externalid"
    response = requests.get(url,
        params={"externalId": external_id},
        headers={"Authorization": f"{API_KEY}"}
    )
    if response.status_code == 200:
        return response.json()['data']['kruncherId']
    return None
 
# Usage: Convert between systems
external_id = get_external_id("proj_123")  # Kruncher → External
kruncher_id = get_kruncher_id("affinity_org_456")  # External → Kruncher
 
if external_id and kruncher_id:
    print(f"Sync data between {kruncher_id} and {external_id}")

When to use: Converting IDs between systems, quick bidirectional lookups.

Pattern 3: Verify Before Processing (Direct Endpoint)

CODE
async function processCompany(kruncherId) {
  const url = `https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=${kruncherId}`;
  
  const response = await fetch(url, {
    headers: {
      "Authorization": `YOUR_API_KEY`,
      "Content-Type": "application/json"
    }
  });
  
  // Check if mapping exists
  if (response.status === 404) {
    console.log("Company not mapped");
    return;
  }
  
  if (!response.ok) {
    throw new Error(`Error: ${response.statusText}`);
  }
  
  const result = await response.json();
  const mapping = result.data;
  
  // Check mapping age
  const createdDate = new Date(mapping.createdAt);
  const ageInDays = Math.floor((Date.now() - createdDate) / (1000 * 60 * 60 * 24));
  
  if (ageInDays > 90) {
    console.warn(`Warning: Mapping is ${ageInDays} days old`);
  }
  
  // Process company
  await processExternal(mapping);
}

When to use: Validation before processing, checking if entity is mapped.

Performance Tips

When to Use Direct Query Endpoints

Use /map/kruncherid or /map/externalid for:

  • Single lookups - No need to fetch all mappings
  • High-frequency calls - Each lookup is independent
  • Low latency requirements - Smaller response, faster processing
  • Memory-constrained environments - Don’t cache entire dataset
CODE
// Fast single lookup (recommended)
const mapping = await getMappingByKruncherId("proj_123");

When to Use /map/all

Use /map/all with client-side filtering for:

  • Batch lookups - 3+ IDs to look up at once
  • Provider filtering - Need to filter by specific provider
  • Caching strategy - Cache once, query many times
  • Complete dataset - Need all mappings anyway
CODE
// Batch lookup with caching (recommended)
const lookup = new MappingLookup(API_KEY);
const ids = ["proj_1", "proj_2", "proj_3"];
const mappings = ids.map(id => lookup.getMapping(id, "affinity"));

Caching Strategy for /map/all

If using /map/all, implement caching:

  • Cache mappings for 10 minutes
  • Refresh cache after creating new mappings
  • Use indices for O(1) lookups
  • Share cache across requests
CODE
// Indexed lookup with caching
const lookup = new MappingLookup(API_KEY);
const mapping = await lookup.getMapping(kruncherId, provider);

Batch Operations

CODE
// Get all at once, then filter (if needed)
const mappings = await lookup.getMappingsForProvider("affinity");
 
// Or use query endpoint per ID (if only a few)
const externalIds = ["affinity_org_1", "affinity_org_2"];
const batchMappings = await Promise.all(
  externalIds.map(id => getMappingByExternalId(id))
);

Error Handling

Mapping Not Found (Query Endpoints)

Query endpoints return 404 when no mapping exists. This is normal and expected.

CODE
// Using direct query endpoint
const response = await fetch(
  `https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=proj_123`,
  { headers: { "Authorization": `${API_KEY}` } }
);
 
if (response.status === 404) {
  console.log("Mapping not found. Options:");
  console.log("1. Create the mapping first via POST /config/mapping");
  console.log("2. Verify the Kruncher ID is correct");
  console.log("3. Check if mapped to a different provider");
  return;
}
 
if (!response.ok) {
  throw new Error(`Error: ${response.statusText}`);
}
 
const mapping = (await response.json()).data;

Mapping Not Found (Get All Approach)

CODE
lookup = MappingLookup()
mapping = lookup.get_mapping("proj_123", "affinity")
 
if not mapping:
    print("Mapping not found. Options:")
    print("1. Create the mapping first")
    print("2. Check provider name is correct")
    print("3. Verify Kruncher ID exists")

Stale Mapping

CODE
import requests
from datetime import datetime
 
# Get mapping and check age
response = requests.get(
    "https://api.kruncher.ai/api/integration/map/kruncherid",
    params={"kruncherId": "proj_123"},
    headers={"Authorization": f"{API_KEY}"}
)
 
if response.status_code == 200:
    mapping = response.json()['data']
    created_date = datetime.fromisoformat(mapping['createdAt'].replace('Z', '+00:00'))
    age_days = (datetime.now(created_date.tzinfo) - created_date).days
    
    if age_days > 90:
        print(f"Warning: Mapping is {age_days} days old, may need refresh")
        # Re-sync with external system

Invalid Query Parameters

CODE
# Missing required parameter
curl -X GET "https://api.kruncher.ai/api/integration/map/kruncherid" \
  -H "Authorization: YOUR_API_KEY_HERE"
# Response: 400 Bad Request - "kruncherId parameter is required"
 
# Properly formatted request
curl -X GET "https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=proj_123" \
  -H "Authorization: YOUR_API_KEY_HERE"
# Response: 200 OK with mapping data

Best Practices

Before Syncing

  • Verify mapping exists
  • Check mapping is recent (< 90 days old)
  • Log sync operations
  • Handle missing mappings gracefully

Performance

  • Cache mappings locally
  • Use indexed lookups
  • Batch operations when possible
  • Refresh cache periodically

Error Handling

  • Handle “not found” gracefully
  • Provide helpful error messages
  • Log all mapping lookups
  • Implement retry logic

Data Integrity

  • Validate ID format before lookup
  • Verify entity exists in both systems
  • Monitor sync success rates
  • Alert on mapping anomalies

Troubleshooting

Mapping Not Found

  • Verify mapping was created
  • Check provider name spelling
  • Ensure you’re using correct Kruncher ID
  • Confirm account has access

Performance Issues

  • Large number of mappings (>10,000)
  • Implement client-side caching
  • Use batch lookups
  • Consider indexing strategy

Stale Data

  • Cache too old, refresh needed
  • Recent sync deleted mapping
  • Verify mapping still exists
  • Check for conflicts

Need Help?

  • Can’t find mapping? Check Create Mapping guide
  • Bulk lookups? Review batch operation examples
  • Performance? Implement caching pattern above
  • Sync issues? Debug with mapping info tool
Last updated on