fastify-xrcs
getTemplate
Fetch a registered Twilio Content API template by its SID.
getTemplate
Fetches a registered Twilio Content API template by its SID. Useful for verifying a template exists before sending or for displaying template details in an admin UI.
Signature
fastify.xrcs.getTemplate(contentSid: string): Promise<RegisteredTemplate>
Params
| Name | Type | Required | Description |
|---|---|---|---|
contentSid | string | Yes | The Twilio Content API template SID (e.g. "HXabc123...") |
Returns
{
sid: string,
friendlyName: string,
language: string,
types: object,
dateCreated: Date
}
Throws
[xRCS] Twilio credentials required— no credentials at registration[xRCS] 'contentSid' must be a non-empty string— missing or invalid SID[xRCS] Failed to get template '{contentSid}': {message}— Twilio API error (e.g. 404 not found)
Examples
Fetch template details in a route
fastify.get("/templates/:sid", async (request, reply) => {
const template = await fastify.xrcs.getTemplate(request.params.sid);
return template;
});
Verify a template before bulk send
async function sendBulkNotification(phones, templateSid) {
// Verify template exists first
await fastify.xrcs.getTemplate(templateSid);
return Promise.all(
phones.map((phone) => fastify.xrcs.sendMessage(phone, templateSid))
);
}
See Also
- listTemplates(limit?) — list all templates
- deleteTemplate(contentSid) — delete a template by SID
AI Context
package: "@xenterprises/fastify-xrcs"
method: fastify.xrcs.getTemplate(contentSid)
use-when: Fetch a Twilio Content API template by SID
returns: template object with friendly name, content type, and variables
requires: Twilio credentials
