How To Manage Team Departments On WhatsApp Using PHP

March 13, 2025

Efficient communication is key for any business, and with Wassenger’s Departments feature, you can organize your team members by speciality, ensuring chats are assigned to the right people effortlessly. 🚀

In this guide, we’ll show you how to use PHP and Wassenger API to:

  1. Get team departments
  2. Create a new department
  3. Update a department
  4. Delete a department
  5. Assign chats to departments

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Why Use Departments in Wassenger? 🤔

With Departments, you can:

Organize Your Team — Group team members by function or expertise.  ✅ Improve Chat Routing — Automatically assign incoming chats to the right department or user.  ✅ Enhance Efficiency — Reduce response time by sending chats directly to those best suited to handle them.  ✅ Seamlessly Integrate with Team Roles — Works alongside administrator, supervisor, and agent roles without changing their default permissions.

🔗 Want to learn more about Departments? Check out the full guide here

Requirements

  1. By using the API, query the available departments in your device for this endpoint.

1. GET Departments with PHP

Target API URL using the GET method

http://api.wassenger.com/v1/devices/{device_id}/departments

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Get departments

Get Departments with 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();

Get Departments with 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();

Get Departments with 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. CREATE a New Department with PHP

Target API URL using the POST method

http://api.wassenger.com/v1/devices/{device_id}/departments

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Create Department

{{AGENT_ID}} : Replace this expression with the specific value

Create Departments with 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();

Create Departments with 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();

Create Departments with 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 is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

3. UPDATE Department with PHP

Target API URL using the PATCH method

http://api.wassenger.com/v1/devices/{device_id}/departments

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Update Department

{{DEPARTMENT_ID}} : Replace this expression with the specific value

{{AGENT_ID}} : Replace this expression with the specific value

Update Departments with 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();

Update Departments with 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();

Update Departments with 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. DELETE Department with PHP

Target API URL using the DELETE method

http://api.wassenger.com/v1/devices/{device_id}/departments

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Delete Department

{{DEPARTMENT_ID}} : Replace this expression with the specific value

Delete Departments with 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();

Delete Departments with 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();

Delete Departments with 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 is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

Live testing to send a message to a group via API

Try our API-Live tester now!

Managing departments with Wassenger API in PHP allows businesses to streamline chat assignments, improve efficiency, and keep conversations organized without hassle.

📌 Stop juggling chat assignments manually! Automate, optimize, and scale your business effortlessly with Wassenger. Start your free trial now!

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free