Create a template

SDK platic.whatsapp.templates.create()

Create a template in the workspace's WhatsApp Business account (WABA) and submit it to Meta for review. It remains PENDING until Meta approves it as APPROVED; only then can it be sent.

If your credential covers several workspaces, add ?workspace=<id> (list workspaces); without it the answer is 400.

Example

await platic.whatsapp.templates.create({
  name: "order_update",
  language: "es_MX",
  category: "UTILITY",
  components: [{ type: "BODY", text: "Your order {{1}} is on its way.", example: { body_text: [["1001"]] } }],
});

Request body

{
  "name": "order_update",
  "language": "es_MX",
  "category": "UTILITY",
  "components": [
    {
      "type": "BODY",
      "text": "Hi {{1}}, your order {{2}} is ready for pickup.",
      "example": { "body_text": [["Ana", "A-1024"]] }
    },
    { "type": "FOOTER", "text": "Acme" },
    { "type": "BUTTONS", "buttons": [{ "type": "QUICK_REPLY", "text": "On my way" }] }
  ]
}
ParameterTypeRequiredDescription
namestring✓Template name: only lowercase letters, numbers and underscore, up to 512 characters. It is the one you use when sending it
languagestring✓Meta language code, such as es, es_MX or en_US. es-MX and es_mx are read as es_MX
categorystring✓MARKETING, UTILITY or AUTHENTICATION, in upper or lower case
componentsarray✓From 1 to 20 components in Meta's format, each with its type: HEADER, BODY, FOOTER, BUTTONS or CAROUSEL
wabaIdstring—The WABA to create it in. Only needed if the workspace has several
allowCategoryChangeboolean—true lets Meta move it to the category it considers correct instead of rejecting it
campaignIdstring—The campaign it is for. It stays among the templates that campaign sent for review and is created in the campaign's WABA, unless you indicate another. A campaign that does not exist answers 404 CAMPAIGN_NOT_FOUND
associateWithCampaignboolean—Only with campaignId: true makes it the campaign's chosen template. By default, the campaign keeps the one it had

You can also send wabaId in the query (?wabaId=). If both the query and body include it, the body takes priority. An unrecognized field returns 400.

Components

components follows Meta's format: the reference is in template components. Each variable ({{1}}, {{2}}…) carries an example value in example.

For an image, video or document header, put the file's public URL in example.header_url. Platica downloads it and uploads it to Meta before sending the template.

{
  "type": "HEADER",
  "format": "IMAGE",
  "example": { "header_url": ["https://shop.example.com/img/order.png"] }
}

Response

Returns 201:

{
  "status": "success",
  "message": "Template submitted to Meta's review",
  "data": {
    "name": "order_update",
    "category": "UTILITY",
    "status": "PENDING",
    "language": "es_MX",
    "components": [
      {
        "type": "BODY",
        "text": "Hi {{1}}, your order {{2}} is ready for pickup.",
        "example": { "body_text": [["Ana", "A-1024"]] }
      },
      { "type": "FOOTER", "text": "Acme" },
      { "type": "BUTTONS", "buttons": [{ "type": "QUICK_REPLY", "text": "On my way" }] }
    ],
    "source": "meta",
    "content": "Hi {{1}}, your order {{2}} is ready for pickup.",
    "params": ["Ana", "A-1024"],
    "header": { "type": "none", "requiresMedia": false },
    "footer": "Acme",
    "buttons": [{ "type": "QUICK_REPLY", "text": "On my way" }],
    "id": "1234567890123456",
    "api_example": {
      "name": "order_update",
      "params": ["Ana", "A-1024"]
    },
    "dynamicButtonsCount": 0,
    "wabaId": "155512345678901",
    "workspaceId": "K7u9rQ2LmZx18BvC5tNd",
    "nextStep": "Meta reviews the template before it can be sent. Check its status with GET /v1/whatsapp/templates/order_update and, once it is APPROVED, send it with POST /v1/messages/template."
  }
}
FieldDescription
idTemplate ID at Meta
statusThe status Meta answered. PENDING if it did not say another
categoryThe category Meta registered it with; with allowCategoryChange it can be another
componentsThe components you sent
content, params, header, footer, buttonsThe template in the same shape as get a template
api_exampleThe body to send the template once Meta approves it
wabaId, workspaceIdWhere it ended up
campaignId, associatedWithCampaignOnly with campaignId: the campaign and whether the template became its chosen one
nextStepWhat comes next

Errors

Statusdetails.codeWhen
400INVALID_REQUESTThe body is not valid or has an unknown field. details.issues says which
400INVALID_REQUESTYour credential covers several workspaces and you did not send ?workspace=, or you sent one it does not cover. details.available has the IDs you can use
400WABA_REQUIREDThe workspace has several WABAs and you did not send wabaId. details.available lists them
400TEMPLATE_INVALIDMeta or Platica rejected the template. details.message has the reason
401UNAUTHENTICATEDThe credential is missing or not valid
403FORBIDDENAn OAuth token without the platica:write scope, or the person has no write permission in Conversations or Campaigns. The message is Missing conversations or campaigns permission
404WORKSPACE_NOT_FOUNDThe workspace does not exist
404WABA_NOT_FOUNDThe workspace has no connected WABA, or wabaId is not one of its own. details.available lists the ones it has
404CAMPAIGN_NOT_FOUNDcampaignId is not a campaign of the workspace
409LEGACY_PROVIDERThe workspace sends WhatsApp through MessageBird. Its templates are read here, but created in MessageBird
409WHATSAPP_TOKEN_INVALIDThe WABA's access token expired or was revoked, or Platica has none that works. Reconnect the account in Platica
409WHATSAPP_PERMISSION_DENIEDThe WABA's token is missing a permission. Reconnect the account accepting all the WhatsApp permissions and check in Meta Business Manager that the app still has access to the WABA
409WHATSAPP_ACCOUNT_RESTRICTEDMeta restricted the WABA. Check its status in WhatsApp Manager
429RATE_LIMITEDWhatsApp is rate limiting the account's template requests. Wait a few minutes and try again
502UPSTREAM_ERRORPlatica could not reach WhatsApp. Try again in a moment
502TEMPLATE_ID_MISSINGWith campaignId: Meta created the template but did not return its id, so it did not end up in the campaign. Check it with get a template before trying again
503TEMPORARILY_UNAVAILABLEPlatica could not read the workspace or its WABAs. Try again in a moment
504UPSTREAM_TIMEOUTWhatsApp did not answer in time. The template may or may not have been created: check it with get a template before trying again

For WHATSAPP_TOKEN_INVALID, WHATSAPP_PERMISSION_DENIED, WHATSAPP_ACCOUNT_RESTRICTED, or RATE_LIMITED, check the WhatsApp account. details.metaCode contains Meta's code when available; details.upstreamMessage contains its message. Editing the template does not resolve these errors. UPSTREAM_ERROR may also include details.upstreamMessage.

{
  "code": 400,
  "error": "Bad Request - The request has validation errors",
  "details": {
    "code": "WABA_REQUIRED",
    "message": "This workspace has several WhatsApp Business Accounts. Send wabaId with the one the template belongs to.",
    "available": ["155512345678901", "155598765432109"]
  }
}

The general error format is in Errors.

Notes

  • The rules for names, categories and content are Meta's: check its template guidelines before creating one.
  • If you recently deleted a template with the same name, Meta may reject the new one for a while.
  • To change it later use update a template; to remove it, delete a template.