POST
/
api
/
public
/
contact
/
{aiContactId}
/
assign-team-member
/
{teamMemberId}
Assign an team member to an AI contact
curl --request POST \
  --url https://api.vambe.me/api/public/contact/{aiContactId}/assign-team-member/{teamMemberId} \
  --header 'x-api-key: <x-api-key>'

Overview

Assign a specific team member (agent) to a contact. This creates a direct relationship between the team member and the contact, making the team member responsible for managing that conversation. This is essential for routing conversations to the right person, implementing assignment rules, and ensuring accountability in customer interactions.

Use Cases

  • Manual Assignment: Allow supervisors to manually assign conversations to specific agents
  • Load Balancing: Programmatically distribute contacts across team members
  • Specialized Routing: Assign contacts to agents based on skills, language, or expertise
  • Escalation Workflows: Reassign contacts to senior agents when needed
  • Territory Management: Assign contacts to agents based on geographic region
  • VIP Handling: Route high-value customers to dedicated account managers

Authentication

This endpoint requires authentication using an API key. Include your API key in the request header:
x-api-key: your_api_key_here

Path Parameters

ParameterTypeRequiredDescription
aiContactIdstring (UUID)YesUnique identifier of the contact to assign
teamMemberIdstring (UUID)YesUnique identifier of the team member to assign

Response Structure

The endpoint returns a success response confirming the assignment:
FieldTypeDescription
successbooleanWhether the assignment was successful
messagestringConfirmation message

Example Request

curl --request POST \
  'https://api.vambe.ai/api/public/contact/1937bd2c-a13c-4365-af06-43af9a988e36/assign-team-member/228d7a0d-9072-4ca8-939b-959b75cc606a' \
  --header 'x-api-key: your_api_key_here'

Example Response

{
  "success": true,
  "message": "Team member assigned successfully"
}

Common Use Cases

1. Assign Contact from Dropdown Selection

const assignContactToAgent = async (contactId, agentId) => {
  const response = await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${agentId}`,
    {
      method: 'POST',
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  const result = await response.json();

  if (result.success) {
    console.log('Agent assigned successfully!');
    // Refresh UI or show success message
  }

  return result;
};

// Usage example
// assignContactToAgent('contact-uuid', 'agent-uuid');

2. Round-Robin Assignment

const assignContactRoundRobin = async (contactId) => {
  // Get all team members
  const teamResponse = await fetch(
    'https://api.vambe.ai/api/public/team-members/all',
    {
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  const teamMembers = await teamResponse.json();

  // Simple round-robin: rotate through team members
  const assignmentIndex = await getNextAssignmentIndex(); // Your logic to track rotation
  const selectedAgent = teamMembers[assignmentIndex % teamMembers.length];

  // Assign contact
  const response = await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${selectedAgent.id}`,
    {
      method: 'POST',
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  console.log(`Assigned to ${selectedAgent.name}`);
  return await response.json();
};

3. Skill-Based Assignment

const assignBySkill = async (contactId, requiredSkill) => {
  // Get all team members
  const teamResponse = await fetch(
    'https://api.vambe.ai/api/public/team-members/all',
    {
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  const teamMembers = await teamResponse.json();

  // Your custom logic to map skills to team members
  const skillMap = {
    technical_support: ['228d7a0d-9072-4ca8-939b-959b75cc606a'],
    billing: ['338e8b1e-8183-5db9-a4ab-a6ab86dd717b'],
    sales: ['448f9c2f-9294-6eca-b5bc-b7bc97ee828c'],
  };

  const eligibleAgentIds = skillMap[requiredSkill] || [];
  const selectedAgentId = eligibleAgentIds[0]; // Or use more sophisticated selection

  if (!selectedAgentId) {
    throw new Error(`No agent available for skill: ${requiredSkill}`);
  }

  const response = await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${selectedAgentId}`,
    {
      method: 'POST',
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  return await response.json();
};

4. Reassign to Senior Agent (Escalation)

const escalateToSenior = async (contactId) => {
  const SENIOR_AGENT_ID = '228d7a0d-9072-4ca8-939b-959b75cc606a'; // Your senior agent ID

  const response = await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${SENIOR_AGENT_ID}`,
    {
      method: 'POST',
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  const result = await response.json();

  if (result.success) {
    // Send notification to senior agent
    console.log('Contact escalated to senior agent');
  }

  return result;
};

5. Geographic Territory Assignment

const assignByTerritory = async (contactId, contactPhoneNumber) => {
  // Extract country code from phone number
  const countryCode = contactPhoneNumber.substring(0, 3); // e.g., "+56" for Chile

  // Territory mapping
  const territoryAgents = {
    '+56': '228d7a0d-9072-4ca8-939b-959b75cc606a', // Chile
    '+52': '338e8b1e-8183-5db9-a4ab-a6ab86dd717b', // Mexico
    '+57': '448f9c2f-9294-6eca-b5bc-b7bc97ee828c', // Colombia
  };

  const agentId = territoryAgents[countryCode];

  if (!agentId) {
    console.log('No agent for this territory, using default');
    return;
  }

  const response = await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${agentId}`,
    {
      method: 'POST',
      headers: {
        'x-api-key': 'your_api_key_here',
      },
    },
  );

  return await response.json();
};

6. Bulk Assignment

const bulkAssignContacts = async (contactIds, agentId) => {
  const results = [];

  for (const contactId of contactIds) {
    try {
      const response = await fetch(
        `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${agentId}`,
        {
          method: 'POST',
          headers: {
            'x-api-key': 'your_api_key_here',
          },
        },
      );

      const result = await response.json();
      results.push({ contactId, success: result.success });
    } catch (error) {
      results.push({ contactId, success: false, error: error.message });
    }
  }

  console.log(
    `Assigned ${results.filter((r) => r.success).length} of ${contactIds.length} contacts`,
  );

  return results;
};

Assignment Behavior

What Happens When You Assign

  1. Agent Assignment: The team member is added to the contact’s assigned agents list
  2. Notification: The assigned agent may receive a notification (depending on your settings)
  3. Visibility: The contact appears in the agent’s assigned contacts view
  4. Multiple Assignments: A contact can have multiple assigned agents
  5. Activity Log: The assignment is recorded in the contact’s activity history

Replacing vs Adding

  • This endpoint adds the team member to the contact’s assigned agents
  • To replace all assigned agents with a single agent, use the internal assignment endpoint
  • A contact can have multiple assigned team members working together

Error Responses

Status CodeDescription
400Bad Request - Invalid contact or agent ID
401Unauthorized - Invalid or missing API key
404Not Found - Contact or team member not found
500Internal Server Error - Something went wrong

Important Notes

  • Valid IDs Required: Both aiContactId and teamMemberId must be valid UUIDs from your organization
  • Team Member Verification: The team member must exist and be active in your organization
  • Contact Ownership: The contact must belong to your organization
  • Idempotent: Assigning the same agent multiple times won’t create duplicates
  • No Body Required: This is a simple POST with no request body needed
  • Immediate Effect: The assignment takes effect immediately

Best Practices

1. Verify IDs Before Assignment

// Always validate IDs before attempting assignment
const isValidUUID = (id) => {
  const uuidRegex =
    /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
  return uuidRegex.test(id);
};

if (!isValidUUID(contactId) || !isValidUUID(agentId)) {
  console.error('Invalid UUID format');
  return;
}

2. Handle Errors Gracefully

try {
  const result = await assignContactToAgent(contactId, agentId);
  // Success handling
} catch (error) {
  if (error.status === 404) {
    console.error('Contact or agent not found');
  } else if (error.status === 401) {
    console.error('Invalid API key');
  } else {
    console.error('Assignment failed:', error);
  }
}

3. Provide User Feedback

const assignWithFeedback = async (contactId, agentId, agentName) => {
  // Show loading state
  showLoading('Assigning agent...');

  try {
    const response = await fetch(
      `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${agentId}`,
      {
        method: 'POST',
        headers: {
          'x-api-key': 'your_api_key_here',
        },
      },
    );

    const result = await response.json();

    if (result.success) {
      showSuccess(`Successfully assigned to ${agentName}`);
    } else {
      showError('Assignment failed');
    }
  } catch (error) {
    showError(`Error: ${error.message}`);
  } finally {
    hideLoading();
  }
};

Workflow Example

Complete workflow for assignment UI:
// 1. Load team members
const teamMembers = await fetch(
  'https://api.vambe.ai/api/public/team-members/all',
  {
    headers: { 'x-api-key': 'your_api_key_here' },
  },
).then((r) => r.json());

// 2. Display in dropdown
// <Select options={teamMembers.map(m => ({ value: m.id, label: m.name }))} />

// 3. On selection, assign
const handleAssignment = async (selectedAgentId) => {
  await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/assign-team-member/${selectedAgentId}`,
    {
      method: 'POST',
      headers: { 'x-api-key': 'your_api_key_here' },
    },
  );

  // 4. Refresh contact info
  const updatedContact = await fetch(
    `https://api.vambe.ai/api/public/contact/${contactId}/info`,
    {
      headers: { 'x-api-key': 'your_api_key_here' },
    },
  ).then((r) => r.json());

  console.log('Contact updated:', updatedContact);
};

Headers

x-api-key
string
required

API key required to authorize the request

Path Parameters

aiContactId
string
required

ID of the AI contact

teamMemberId
string
required

ID of the team member

Response

Team member assigned successfully.