La comunicación eficiente es clave para cualquier negocio, y con la función Departamentos de Wassenger, puedes organizar a los miembros de tu equipo por especialidad, asegurando que los chats se asignen a las personas correctas sin esfuerzo. 🚀
En esta guía, te mostraremos cómo usar PHP y la API de Wassenger para:
- Obtener los departamentos del equipo
- Crear un nuevo departamento
- Actualizar un departamento
- Eliminar un departamento
- Asignar chats a departamentos
🤩 🤖 Wassenger es una solución API completa para WhatsApp. Regístrate para una prueba gratuita de 7 días y comienza en minutos!
¿Por qué usar Departamentos en Wassenger? 🤔
Con Departamentos, puedes:
✅ Organizar tu equipo — Agrupa a los miembros por función o experiencia.
✅ Mejorar el enrutamiento de chats — Asigna automáticamente los chats entrantes al departamento o usuario correcto.
✅ Aumentar la eficiencia — Reduce el tiempo de respuesta enviando chats directamente a quienes mejor pueden atenderlos.
✅ Integrarse sin problemas con los roles del equipo — Funciona junto con los roles de administrador, supervisor y agente sin cambiar sus permisos predeterminados.
🔗 ¿Quieres saber más sobre Departamentos? Consulta la guía completa aquí
Requisitos
- Tener un número de WhatsApp ya vinculado a la plataforma y en línea.
- Usando la API, consulta los departamentos disponibles en tu dispositivo con este endpoint.
1. Obtener Departamentos con PHP
URL objetivo de la API usando el método GET
http://api.wassenger.com/v1/devices/{device_id}/departments
Encabezados HTTPS requeridos > Obtén tu clave API aquí
Content-Type: application/json
Token: $API_TOKEN
Obtener departamentos
Obtener departamentos con PHP (Guzzle)
// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP.
// Install it first following these instructions:
// https://docs.guzzlephp.org/en/stable/overview.html#installation
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request(
'GET',
'https://api.wassenger.com/v1/devices/device.id/departments',
[
'headers' => [
'Token' => 'ENTER API KEY HERE',
],
]
);
echo $response->getBody();
Obtener departamentos con PHP (http2)
// This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://mdref.m6w6.name/http
<?php
$client = new http\Client();
$request = new http\Client\Request();
$request->setRequestUrl(
'https://api.wassenger.com/v1/devices/device.id/departments'
);
$request->setRequestMethod('GET');
$request->setHeaders([
'Token' => 'ENTER API KEY HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Obtener departamentos con PHP (curl)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/devices/{{device.id}}/departments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => ['Token: ENTER API KEY HERE'],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
2. Crear un nuevo Departamento con PHP
URL objetivo de la API usando el método POST
http://api.wassenger.com/v1/devices/{device_id}/departments
Encabezados HTTPS requeridos > Obtén tu clave API aquí
Content-Type: application/json
Token: $API_TOKEN
Crear departamento
{{AGENT_ID}} : Reemplaza esta expresión con el valor específico
Crear departamentos con PHP (Guzzle)
// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP.
// Install it first following these instructions:
// https://docs.guzzlephp.org/en/stable/overview.html#installation
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request(
'POST',
'https://api.wassenger.com/v1/devices/device.id/departments',
[
'body' =>
'{"name":"Sales", "color":"orange", "description":"Department for the Sales team", "agents":["{{AGENT_ID}}"]}',
'headers' => [
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE',
],
]
);
echo $response->getBody();
Crear departamentos con PHP (http2)
// This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://mdref.m6w6.name/http
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
json_encode([
'name' => 'Sales',
'color' => 'orange',
'description' => 'Department for the Sales team',
'agents' => ['{{AGENT_ID}}'],
])
);
$request->setRequestUrl(
'https://api.wassenger.com/v1/devices/device.id/departments'
);
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Crear departamentos con PHP (curl)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/devices/{{device.id}}/departments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Sales',
'color' => 'orange',
'description' => 'Department for the Sales team',
'agents' => ['{{AGENT_ID}}'],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: ENTER API KEY HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
🤩 🤖 Wassenger es una solución API completa para WhatsApp. Regístrate para una prueba gratuita de 7 días y comienza en minutos!
3. Actualizar Departamento con PHP
URL objetivo de la API usando el método PATCH
http://api.wassenger.com/v1/devices/{device_id}/departments
Encabezados HTTPS requeridos > Obtén tu clave API aquí
Content-Type: application/json
Token: $API_TOKEN
Actualizar departamento
{{DEPARTMENT_ID}} : Reemplaza esta expresión con el valor específico
{{AGENT_ID}} : Reemplaza esta expresión con el valor específico
Actualizar departamentos con PHP (Guzzle)
// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP.
// Install it first following these instructions:
// https://docs.guzzlephp.org/en/stable/overview.html#installation
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('PATCH', 'https://api.wassenger.com/v1/team', [
'body' =>
'{"department":"{{DEPARTMENT_ID}}", "name":"Marketing", "color":"purple", "description":"Department for the Marketing team", "agents":["{{AGENT_ID}}"]}',
'headers' => [
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE',
],
]);
echo $response->getBody();
Actualizar departamentos con PHP (http2)
// This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://mdref.m6w6.name/http
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
json_encode([
'department' => '{{DEPARTMENT_ID}}',
'name' => 'Marketing',
'color' => 'purple',
'description' => 'Department for the Marketing team',
'agents' => ['{{AGENT_ID}}'],
])
);
$request->setRequestUrl('https://api.wassenger.com/v1/team');
$request->setRequestMethod('PATCH');
$request->setBody($body);
$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Actualizar departamentos con PHP (curl)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/team',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS => json_encode([
'department' => '{{DEPARTMENT_ID}}',
'name' => 'Marketing',
'color' => 'purple',
'description' => 'Department for the Marketing team',
'agents' => ['{{AGENT_ID}}'],
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: ENTER API KEY HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
4. Eliminar Departamento con PHP
URL objetivo de la API usando el método DELETE
http://api.wassenger.com/v1/devices/{device_id}/departments
Encabezados HTTPS requeridos > Obtén tu clave API aquí
Content-Type: application/json
Token: $API_TOKEN
Eliminar departamento
{{DEPARTMENT_ID}} : Reemplaza esta expresión con el valor específico
Eliminar departamentos con PHP (Guzzle)
// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP.
// Install it first following these instructions:
// https://docs.guzzlephp.org/en/stable/overview.html#installation
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request(
'DELETE',
'https://api.wassenger.com/v1/devices/device.id/departments',
[
'body' => '{"department":"{{DEPARTMENT_ID}}"}',
'headers' => [
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE',
],
]
);
echo $response->getBody();
Eliminar departamentos con PHP (http2)
// This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP.
// Install it by running: pecl install pecl_http
// More information: https://mdref.m6w6.name/http
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
json_encode([
'department' => '{{DEPARTMENT_ID}}',
])
);
$request->setRequestUrl(
'https://api.wassenger.com/v1/devices/device.id/departments'
);
$request->setRequestMethod('DELETE');
$request->setBody($body);
$request->setHeaders([
'Content-Type' => 'application/json',
'Token' => 'ENTER API KEY HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
Eliminar departamentos con PHP (curl)
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.wassenger.com/v1/devices/{{device.id}}/departments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_POSTFIELDS => json_encode([
'department' => '{{DEPARTMENT_ID}}',
]),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Token: ENTER API KEY HERE',
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
echo $response;
}
🤩 🤖 Wassenger es una plataforma de comunicación y solución API completa para WhatsApp. Explora más de 100 casos de uso de la API y automatiza cualquier cosa en WhatsApp registrándote para una prueba gratuita y comenzando en minutos!
Prueba en vivo para enviar un mensaje a un grupo vía API
¡Prueba nuestro API-Live tester ahora!
Gestionar departamentos con la API de Wassenger en PHP permite a las empresas optimizar las asignaciones de chats, mejorar la eficiencia y mantener las conversaciones organizadas sin complicaciones.
📌 Deja de asignar chats manualmente! Automatiza, optimiza y escala tu negocio sin esfuerzo con Wassenger. ¡Comienza tu prueba gratuita ahora!







