// Complete workflow: Create ticket with metadata, then update it
const createAndEnrichContact = async (phoneNumber, initialData) => {
// 1. Create ticket/contact
const createResponse = await fetch(
'https://api.vambe.ai/api/public/ticket/open/web-whatsapp/your_phone_id',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'your_api_key_here',
},
body: JSON.stringify({
to_phone_number: phoneNumber,
stage_id: 'your_stage_id',
contact_name: initialData.name,
contact_metadata: {
source: initialData.source,
},
}),
},
);
const { aiContactId } = await createResponse.json();
// 2. Enrich with additional metadata after qualification
const enrichResponse = await fetch(
`https://api.vambe.ai/api/public/contact/${aiContactId}/update-metadata`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'your_api_key_here',
},
body: JSON.stringify({
company: initialData.company,
industry: initialData.industry,
employeeCount: initialData.size,
leadScore: calculateLeadScore(initialData),
enrichedAt: new Date().toISOString(),
dataQuality: 'High',
}),
},
);
const metadata = await enrichResponse.json();
console.log(`Created and enriched contact ${aiContactId}`);
console.log(`Updated ${metadata.length} metadata fields`);
return { aiContactId, metadata };
};