The following table contains the requirements for all API calls to the endpoints defined in this reference.
| Requirement | Description |
|---|---|
Access token type | Page |
Permission |
|
Get a list of message templates owned or managed by your app user's Facebook Page.
GET /v25.0/{page-id}/message_templates HTTP/1.1
Host: graph.facebook.com/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{page-id}/message_templates',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result *//* make the API call */
FB.api(
"/{page-id}/message_templates",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{page-id}/message_templates",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/{page-id}/message_templates"
parameters:params
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];GET /<PAGE_ID>/message_templates ?category=<CATEGORY>, &content=<CONTENT>, &language=<LANGUAGE>, &name=<NAME>, &name_or_content=<NAME_OR_CONTENT>, &status=<STATUS>
{
"data": [
"name": "order_delivery_update_1",
"components": [
{
"type": "BODY",
"text": "Good news {{1}}! Your order #{{2}} is on its way. Thank you!",
"example": {
"body_text": [
[
"Mark",
"566701"
]
]
}
},
{
"type": "BUTTONS",
"buttons": [
{
"type": "POSTBACK",
"text": "Track Order",
"payload": "track_order"
},
{
"type": "POSTBACK",
"text": "Stop Delivery Update",
"payload": "stop_delivery_update"
}
]
}
],
"language": "en",
"status": "APPROVED",
"category": "UTILITY",
"id": "12345678910123"
},
...
],
"paging": {
"cursors": {
"before": "MAZDZD",
"after": "MjQZD"
}
}
}
| Parameter | Description |
|---|---|
categoryarray<enum {UTILITY}> | The message template category. |
contentstring | The content of the template. |
languagearray<string> | A list of supported languages that are available for each template. |
namestring | The name of the template. |
name_or_contentstring | A list of message templates where the name or content match this value. |
statusarray<enum {APPROVED, IN_APPEAL, PENDING, REJECTED, PENDING_DELETION, DELETED, DISABLED, PAUSED, LIMIT_EXCEEDED, ARCHIVED}> | The review status of the template. |
Reading from this edge will return a JSON formatted result:
{ "
data": [], "paging": {} }
datapaging| Error | Description |
|---|---|
| 200 | Permissions error |
| 100 | Invalid parameter |
message_templates edge from the following paths: To create a utility message template, send a POST request to the /<PAGE_ID>/message_templates endpoint with the following required parameters:
name set to the name of the templatelanguage set to the language of the message textcategory set to UTILITYcomponents set to an array of message components including an example with message valuesTemplates support two parameter formats:
Named parameters — Placeholders use descriptive names: {{customer_name}}, {{order_id}}. Set parameter_format to NAMED when creating the template. Example values are provided in the body_text_named_params and header_text_named_params fields using param_name and example pairs.
Positional parameters (default) — Placeholders use sequential numbers: {{1}}, {{2}}, {{3}}. Example values are provided in the body_text and header_text fields. This is the default format when parameter_format is not specified.
In the following example, we use named parameters with descriptive placeholder names. The parameter_format is set to NAMED, and example values are provided using body_text_named_params and header_text_named_params with param_name and example pairs.
curl -H 'Content-Type: application/json' \
-d '{
"name": "jaspers_market_order_delivery_update_named_us",
"language": "en",
"category": "UTILITY",
"parameter_format": "NAMED",
"components": [
{
"type": "HEADER",
"format": "TEXT",
"text":"{{order_type}} Update",
"example": {
"header_text_named_params": [
{
"param_name": "order_type",
"example": "Order"
}
]
}
},
{
"type": "BODY",
"text": "Good news! Your order #{{order_id}} is on its way. Thank you for your order, {{customer_name}}!",
"example": {
"body_text_named_params": [
{
"param_name": "order_id",
"example": "566701"
},
{
"param_name": "customer_name",
"example": "John"
}
]
}
}
]
}' "https://graph.facebook.com/v25.0/102290129340398/message_templates?access_token=EAAJB..."
In the following example, we have message body text and header text. The body component and header component includes example customer information that would be used to customize the message.
curl -H 'Content-Type: application/json' \
-d '{
"name": "jaspers_market_order_delivery_update_us",
"language": "en",
"category": "UTILITY",
"components": [
{
"type": "HEADER",
"format": "TEXT",
"text":"{{1}} Update",
"example": {
"header_text":["Order"]
}
},
{
"type": "BODY",
"text": "Good news! Your order #{{1}} is on its way. Thank you for your order!",
"example": {
"body_text": [
[
"566701"
]
]
}
}
]
}' "https://graph.facebook.com/v25.0/102290129340398/message_templates?access_token=EAAJB..."
You can also create templates with images. Images need to be first uploaded using the Resumable Upload API to generate the handle for the image. You can then use the handle and pass it in the Header component while creating the template.
curl -H 'Content-Type: application/json' \
-d '{
"name": "jaspers_market_order_delivery_update_named_us",
"language": "en",
"category": "UTILITY",
"parameter_format": "NAMED",
"components": [
{
"type": "HEADER",
"format": "IMAGE",
"text":"{{order_type}} Update",
"example": {
"header_handle": ["4:dGVzdF9pbWFn......."],
"header_text_named_params": [
{
"param_name": "order_type",
"example": "Order"
}
]
}
},
{
"type": "BODY",
"text": "Good news! Your order #{{order_id}} is on its way. Thank you for your order, {{customer_name}}!",
"example": {
"body_text_named_params": [
{
"param_name": "order_id",
"example": "566701"
},
{
"param_name": "customer_name",
"example": "John"
}
]
}
}
]
}' "https://graph.facebook.com/v25.0/102290129340398/message_templates?access_token=EAAJB..."
On success your app receives a JSON response with the template ID, the review status, and the template category.
{
"id": "104595129340398",
"status": "APPROVED",
"category": "UTILITY"
}
{
"id": "594425479261596",
"status": "PENDING",
"category": "UTILITY"
}
| Parameter | Description |
|---|---|
categoryenum {UTILITY} | Required. The category of the template. Required |
componentsarray<JSON object> | An array of objects to be included in the message. Can include the header, body, and buttons (phone number, postback, URL). |
languagestring | The language of the message. For example, en_US. Required |
library_template_button_inputsarray<JSON object> | An array of objects that define the type of button and it's contents and actions. |
library_template_namestring | The name of the library the template belongs to. |
namestring | The name of the template. Required |
id: numeric string, status: enum, category: enum, rejection_reason: enum, specific_rejection_reason: enum, | Error | Description |
|---|---|
| 200 | Permissions error |
| 100 | Invalid parameter |
/{page_id}/message_templates.
curl -X DELETE "https://graph.facebook.com/v25.0/102290129340398/message_templates?name=order_confirmation&access_token=EAAJB..."
{
"success": true
}
| Parameter | Description |
|---|---|
namestring | The name of the template to be deleted in all languages, if no template_id is provided. Required |
template_idnumeric string | Optional. Limits the deletion of template to the template_id provided. |
success: bool, | Error | Description |
|---|---|
| 200 | Permissions error |
| Error | Description |
|---|---|
32 | Your app is rate limited. There have been too many calls to this Page. Wait a bit and try again. For more info, please refer to https://developers.facebook.com/docs/graph-api/overview/rate-limiting. |
100 | Invalid parameter. Check spelling and availability of the parameter for the enpoint in your call. |
190 | Invalid OAuth 2.0 Access Token. Use the Access token debugger tool to help you debug this issue. |
200 | Permissions error. The API call is missing a permission. Use the Access token debugger tool to help you debug this issue. |
368 | The action attempted has been deemed abusive or is otherwise disallowed. |
131009 | Parameter value is not valid. |
200002 | Template creation failed. |