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
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Your API key (format: YOUR_API_KEY) |
Content-Type | No | Optional application/json |
Query Parameters
externalId Endpoint
| Parameter | Required | Description |
|---|---|---|
externalId | Yes | The external system ID to lookup |
Example: /api/integration/map/externalid?externalId=affinity_org_456
kruncherId Endpoint
| Parameter | Required | Description |
|---|---|---|
kruncherId | Yes | The 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
curl -X GET "https://api.kruncher.ai/api/integration/map/externalid?externalId=affinity_org_456" \
-H "Authorization: YOUR_API_KEY_HERE"Response:
{
"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
curl -X GET "https://api.kruncher.ai/api/integration/map/kruncherid?kruncherId=proj_123" \
-H "Authorization: YOUR_API_KEY_HERE"Response:
{
"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
Query: By Kruncher ID
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
Query: By Kruncher ID
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
Query: By Kruncher ID
# 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
{
"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
| Field | Type | Description |
|---|---|---|
id | string | Unique mapping identifier |
entityType | string | Type: person, company, or opportunity |
provider | string | External provider (affinity, attio, pipedrive, etc.) |
kruncherId | string | Kruncher internal ID |
externalId | string | External system ID |
createdAt | string | ISO 8601 timestamp when created |
updatedAt | string | ISO 8601 timestamp when last updated |
customerId | string | Your customer/account ID |
Endpoint Comparison
Which Endpoint Should I Use?
| Use Case | Endpoint | Pros | Cons |
|---|---|---|---|
| Single lookup by Kruncher ID | /map/kruncherid?kruncherId=... | Fast, simple, server-side | Only one ID per request |
| Single lookup by external ID | /map/externalid?externalId=... | Fast, simple, server-side | Only one ID per request |
| Batch lookups (multiple IDs) | /map/all + filter | Get all at once, flexible | Slower, larger response |
| Filter by provider | /map/all + filter | Provider-specific results | Client-side processing |
| Check mapping exists | /map/kruncherid or /map/externalid | Quick verification | Need to handle 404 |
| Get all mappings | /map/all | Complete dataset | Largest response, slower |
Decision Tree:
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 filterPerformance Characteristics
| Endpoint | Request Size | Response Size | Latency | Best For |
|---|---|---|---|---|
/map/kruncherid | Small | Small | Fast | Single Kruncher lookups |
/map/externalid | Small | Small | Fast | Single external lookups |
/map/all | Small | Large | Medium | Batch operations, filtering |
Common Patterns
Pattern 1: Before Syncing Data (Direct Lookup)
// 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)
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)
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
// 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
// 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
// Indexed lookup with caching
const lookup = new MappingLookup(API_KEY);
const mapping = await lookup.getMapping(kruncherId, provider);Batch Operations
// 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.
// 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)
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
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 systemInvalid Query Parameters
# 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 dataRelated Endpoints
- Create Mapping - Create new mappings
- Get All Mappings - List all mappings
- Find Companies - Get Kruncher entity IDs
- Integrations - Provider-specific docs
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