Skip to content

Get All Contacts

Retrieve all contacts for a session with optional pagination and sorting.

Usage

You can use the Contact facade to get all contacts.

php
use NjoguAmos\Waha\Facades\Contact;

$contacts = Contact::all();
php
use NjoguAmos\Waha\Facades\Contact;

$contacts = Contact::all(limit: 50, offset: 0);
php
use NjoguAmos\Waha\Facades\Contact;

$contacts = Contact::all(sortBy: 'name', sortOrder: 'asc');
php
use NjoguAmos\Waha\Facades\Contact;

$contacts = Contact::all(sortBy: 'name', sortOrder: 'asc', limit: 50, offset: 0);
php
use NjoguAmos\Waha\Facades\Contact;

$contacts = Contact::all(session: 'my-session');

Parameters

ParameterTypeRequiredDefaultDescription
sortBystringNonameSort by field: id or name
sortOrderstringNodescSort order: desc (Z→A) or asc (A→Z)
limitintNo100Number of contacts to return
offsetintNo0Number of contacts to skip
sessionstringNodefaultSession name (defaults to waha.session config)

Response

The response returned by the all method is an instance of Saloon\Http\Response. You may use the json method to retrieve the response as an array or the dtoOrFail method to retrieve an array of ContactData DTOs:

php
/** @var \Saloon\Http\Response $response */

$response->status(); // 200
$response->json();   // [["id" => "[email protected]", "number" => "11231231231", ...]]
php
use NjoguAmos\Waha\Facades\Contact;

/** @var \NjoguAmos\Waha\Dto\ContactData[] $contacts */
$contacts = Contact::all()->dtoOrFail();

foreach ($contacts as $contact) {
    $contact->id;          // "[email protected]"
    $contact->number;      // "11231231231"
    $contact->name;        // "Contact Name"
    $contact->pushname;    // "Pushname"
    $contact->shortName;   // "Shortname"
    $contact->isMe;        // true
    $contact->isGroup;     // false
    $contact->isWAContact; // true
    $contact->isMyContact; // true
    $contact->isBlocked;   // false
}

Engines

WEBJSWPPNOWEBGOWS

References

Released under the MIT License.