POST /v1/templates
const url = 'https://seu-endereco-da-api/v1/templates';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"category":"MARKETING","components":[{}],"channelId":"2489E9AD-2EE2-8E00-8EC9-32D5F69181C0","name":"example","language":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://seu-endereco-da-api/v1/templates \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "category": "MARKETING", "components": [ {} ], "channelId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "name": "example", "language": "example" }'Permissão que a Chave de acesso precisa: Gerenciar modelos e formulários (templates:manage).
Authorizations
Seção intitulada “Authorizations”Request Bodyrequired
Seção intitulada “Request Bodyrequired”object
MARKETING and UTILITY take exactly one BODY { type, text, examples? } (up to 1024 characters, {{1}}, {{2}}… numbered from 1, examples is an array with one sample text per variable), an optional HEADER, an optional FOOTER { type, text } (up to 60 characters, no variable) and an optional BUTTONS { type, buttons }. HEADER is { type, format: “TEXT”, text, example? } (up to 60 characters, at most one variable, example is one text) or { type, format: “IMAGE” | “VIDEO” | “DOCUMENT” } with exactly one of: mediaUrl (a public https link to the file, downloaded and sent to Meta by the server), mediaId (a WhatsApp media id of the number, downloaded from Meta) or handle (a Meta upload handle, which may come with the mediaKey and mediaMime the media upload returned). IMAGE takes jpeg or png up to 5 MB, VIDEO mp4 up to 16 MB, DOCUMENT pdf up to 100 MB. BUTTONS takes 1 to 10 buttons, QUICK_REPLY grouped together: QUICK_REPLY { type, text }, URL { type, text, url, example? } (at most 2; a {{1}} goes at the end of the url and example is one text with the full URL, e.g. “https://loja.com/pedido/123”), PHONE_NUMBER { type, text, phoneNumber } (at most 1), COPY_CODE { type, example } (coupon code up to 15 characters, at most 1) and FLOW { type, text, flowId | flowName, flowAction?: “navigate” | “data_exchange”, navigateScreen? } (a published WhatsApp Flow, at most 1); button text up to 25 characters. Payment buttons stand alone: 1 to 3 PAYMENT_REQUEST { type, method: “pix” | “boleto” | “payment_link” } with distinct methods, or exactly one ORDER_DETAILS { type, text } (1 to 25 characters), in a UTILITY or MARKETING template with a NONE or TEXT header; an ORDER_DETAILS template is submitted with display_format ORDER_DETAILS. CAROUSEL { type, cards } turns the template into a carousel: only BODY and CAROUSEL, 2 to 10 cards, each { mediaFormat: “IMAGE” | “VIDEO”, mediaUrl | mediaId, body?, bodyExamples?, buttons } with a body up to 160 characters, 1 or 2 buttons, the same media format on every card and the same buttons, in the same order and of the same types, on every card. AUTHENTICATION takes { type: “BODY”, addSecurityRecommendation? } (Meta writes the text with the code), an optional { type: “FOOTER”, codeExpirationMinutes } (1 to 90) and { type: “BUTTONS”, buttons: [{ type: “OTP”, otpType: “COPY_CODE”, text? }] }, without header. A component outside these formats comes back as 400 with what is wrong and the right format, before anything goes to Meta.