Browse documentation

Messaging

Listing templates

Find existing approved templates and the language and parameter data needed to send them.

DevelopersAdvancedAvailable

What this guide covers

  • Filter the catalog to templates available for the selected Sender.
  • Use only approved templates for production sends.
  • Map application data to the template's declared components.

Read a Sender's approved catalog

GET /v1/templates requires templates:read. The from query is required and must be an E.164 Sender available to the current key.

The catalog is Sender-specific. A template name and language approved for one WhatsApp Business Account must not be assumed to exist for another Sender.

List approved templates
ts
import { WhatsAppClient } from "@yanola/whatsapp"

const apiKey = process.env.YANOLA_API_KEY

if (!apiKey) {
  throw new Error("Missing YANOLA_API_KEY")
}

const yanola = new WhatsAppClient({ apiKey })

const catalog = await yanola.templates.list({
  from: "+15557654321",
  limit: 100,
})

for (const template of catalog.data) {
  console.log(
    template.name,
    template.languageCode,
    template.category
  )
}

Catalog response

Template catalog fields
FieldMeaning
data[].nameTemplate name to pass to messages.sendTemplate.
data[].languageCodeApproved language code; pass it exactly as returned.
data[].statusPublic catalog entries are approved; the SDK type also reserves paused and disabled states.
data[].categoryProvider message category captured for the approved template.
data[].componentsDeclared component structure, text, format, and examples used to build parameters.
data[].syncedAtTime this template snapshot was synchronized.
senderE.164 Sender whose catalog was queried.
syncedAtSynchronization time shared by this catalog response.

Use cached data or request a refresh

By default, Yanola serves the approved catalog from its managed cache. Pass refresh: true only when you need Yanola to request a fresh provider snapshot.

A forced refresh requires a Live Mode key. Test Mode reads the cached approved catalog and returns 422 template_refresh_live_mode_required if refresh is true.

Force a Live Mode refresh
ts
import { WhatsAppClient } from "@yanola/whatsapp"

const apiKey = process.env.YANOLA_API_KEY

if (!apiKey) {
  throw new Error("Missing YANOLA_API_KEY")
}

const yanola = new WhatsAppClient({ apiKey })

const refreshed = await yanola.templates.list({
  from: "+15557654321",
  refresh: true,
})

console.log(refreshed.syncedAt)

Map a catalog entry to a send

Use the exact name and languageCode from the selected catalog entry. Build component parameters in the order and types declared by components.

Send a listed template
ts
import { WhatsAppClient } from "@yanola/whatsapp"

const apiKey = process.env.YANOLA_API_KEY

if (!apiKey) {
  throw new Error("Missing YANOLA_API_KEY")
}

const yanola = new WhatsAppClient({ apiKey })

const { data } = await yanola.templates.list({
  from: "+15557654321",
})
const template = data.find(
  (item) =>
    item.name === "order_update" &&
    item.languageCode === "en_US"
)

if (!template) {
  throw new Error("Approved template not found")
}

const accepted = await yanola.messages.sendTemplate({
  from: "+15557654321",
  to: "+15551234567",
  name: template.name,
  languageCode: template.languageCode,
  components: [
    {
      type: "body",
      parameters: [{ type: "text", text: "A-1042" }],
    },
  ],
})

console.log(accepted.id)

Paginate a stable snapshot

Template lists use opaque cursor pagination with a default of 20 and a maximum of 100. The cursor is bound to the key, Sender, environment, and catalog synchronization time.

If the catalog changes between pages, Yanola rejects the old cursor with invalid_cursor. Restart the listing so every page comes from one synchronized snapshot.

Template catalog errors

Common template list errors
Status and codeMeaningAction
400 invalid_cursorThe cursor is invalid for this Sender or synchronized snapshot.Restart from the first page.
403 insufficient_scope / sender_access_deniedThe key lacks templates:read or cannot use this Sender.Use an appropriately scoped and permitted key.
422 template_refresh_live_mode_requiredrefresh: true was sent with a Test Mode key.Read the cached catalog or use a Live Mode key.
422 sender_reconnect_requiredYanola cannot refresh through the Sender's provider connection.Reconnect the Sender.
429 template_catalog_refresh_rate_limitedThe provider catalog cannot be refreshed yet.Honor Retry-After and continue using cached data when suitable.
503 template_catalog_unavailableThe cache or provider catalog is temporarily unavailable.Retry only when retryable is true.