← All posts
Tutorial

Search WhatsApp and LINE Contacts via API: Build a Safe Picker

To search a connected WhatsApp or LINE account’s address book through UnifyPort, use GET /v1/accounts/{account_id}/contacts with q. Select the returned contact and retain its conversation_id for the chat destination. You do not need to discover the person through message history first. This is an account-scoped address-book lookup—not a global people search, a message archive, or permission to send.

The List contacts reference describes a real-time provider read, not a local UnifyPort contact database. Contacts are included regardless of message history. The current action support matrix maps contact listing to WhatsApp and LINE; do not infer support for other providers from their ability to receive messages.

Key implementation decisions:

  • Search the selected messaging account’s contacts, not the conversation list.
  • Keep each query and its pagination cursor together.
  • Discard late responses after the operator changes the account or search.
  • Preserve contact identifiers and chat destinations as separate values.
  • Make selecting a contact read-only; sending requires another deliberate action.

WhatsApp’s contact-management announcement describes contacts saved exclusively to WhatsApp. A phone’s address book is therefore not a safe substitute for the connected account’s returned contacts. That announcement provides product context; UnifyPort’s own reference defines this API.

If you are repairing a missing chat rather than choosing a contact, follow the WhatsApp conversation-list filter guide. A contact search answers a different question.

Make a read-only search request

Keep X-Api-Key on your backend. Check that the operator may access the selected account before querying or returning contact data. This illustrative request uses environment variables for your actual account and key; it has not been executed here:

curl --get \
  "https://api.unifyport.ai/v1/accounts/${UNIFYPORT_ACCOUNT_ID}/contacts" \
  -H "X-Api-Key: ${UNIFYPORT_API_KEY}" \
  --data-urlencode "q=Alice" \
  --data-urlencode "limit=50"

The documented q matches display_name, phone, or username. It does not document arbitrary-user discovery, fuzzy matching, or a universal phone-number resolver. A successful empty result means this query returned no contacts, not that the person has no platform account.

Parameter or resultHow to use it
limitPage size, 1–100; default 50
cursorOpaque continuation value; reuse the returned value unchanged
data.itemsContact rows for the current query
data.next_cursor, data.has_moreContinuation information for that query
updated_sinceRFC3339 incremental filter where supported; not a universal synchronization guarantee

Leave updated_since out of an ordinary recipient search unless an intentional incremental view is required. Otherwise, an unchanged contact can be outside the requested scope. The public description does not establish identical incremental behavior for every supported provider.

Give every search its own result state

A picker can show the wrong recipient even when every API call succeeds. Imagine searching one account, switching to another, then receiving the first response last. This is a hypothetical UI race, not a reported incident.

Use this application-side sequence:

  1. On an account or query change, create a new local search generation. Clear the old selection, displayed results, and cursor.
  2. Capture the workspace, provider, account, query, and generation with each backend request.
  3. Apply a response only if that captured context still matches the current search. Cancelling a request can save work, but the context check remains necessary.
  4. Allow only one next-page request at a time for the current generation. Keep the same filters and pass next_cursor without decoding or editing it.
  5. Merge repeated rows by contact id within that account. Detect a repeated cursor or missing continuation while has_more is true; show a diagnostic rather than loop indefinitely.
  6. Keep failed requests distinct from successful empty results. Offer an explicit restart when continuation fails rather than silently combining different searches.

These generations and UI states are local design choices, not additional API fields. Because reads are live, ending pagination does not establish an immutable snapshot. Do not delete CRM contacts because they are absent from a search result.

Select the returned destination, not the display name

Each contact exposes id, conversation_id, display_name, avatar_url, and provider_user_id. Keep the account with the selected row; do not store a name alone and resolve it again at send time.

This small JavaScript helper illustrates selection validation only. Its return object is application state, not a send-request body:

function selectContact(accountId, contact) {
  if (typeof accountId !== 'string' || !accountId ||
      typeof contact?.id !== 'string' || !contact.id ||
      typeof contact.conversation_id !== 'string' ||
      !contact.conversation_id) {
    throw new Error('A returned contact and chat mapping are required');
  }
  return {
    accountId,
    contactId: contact.id,
    conversationId: contact.conversation_id
  };
}

Do not convert identifiers to numbers or manufacture a destination from a phone number. Two contacts can have the same display name. Show enough authorized context to distinguish them without exposing unnecessary personal data.

The LINE identity-scope guide explains why official LINE Login identifiers are not an automatic mapping to this connected-account interface. Likewise, WhatsApp contact-name updates change presentation; they should not silently change the selected recipient.

Acceptance checks and FAQ

Before enabling the picker, test duplicate names, contacts without prior messages, empty results, read failures, repeated cursors, and a response arriving after an account switch. Confirm that changing the query clears the selection and that choosing a row sends nothing. These are proposed tests, not measured results.

Can this search anyone on WhatsApp or LINE?

No. The documented scope is the connected account’s provider address book. It is not a public user directory.

Does finding a contact prove we may message them?

No. Address-book presence does not establish consent, reachability, or delivery. Keep communication authorization and any later send result separate.

Can the same picker list Zalo or Telegram contacts?

Not under the current documented contact-list support. Check the operation-specific matrix instead of assuming every unified API action supports every channel.

Next step and sources

Build the first read-only search against List contacts, then test selection and query-switch behavior before connecting a send control. UnifyPort provides an unofficial interface; this workflow neither grants official platform permissions nor supplies message history.

Sources checked on 2026-11-24:

UnifyPort API

Turn messaging integration into a stable product pipeline.

Start by sending through one API, then bring every inbound message back into your business system with standard events.