# Send Template Message API

The Send Message API endpoint and payload are tailored to each approved template message in your account. To send messages via the API, you’ll need to generate an API endpoint for the specific template you want to use.

<details>

<summary>Create API Endpoint</summary>

1. Sign in to [admin.emovur.com](https://admin.emovur.com/).
2. Navigate to the WhatsApp -> Templates.
3. Scroll to find and select the approved template.
4. Click on **"View/Edit Webhook details"** icon against the  approved template.
5. Click on **"Set Webhook details".**
6. If the header has media then you can choose to use static media or dynamic media, If not you will be taken to the final step:
   1. Dynamic - Use a public URL to pass the header media dynamically.
   2. Fixed- Select the source as a URL or upload an image, document, or video to use fixed header media.
7. Click on **"Submit".**
8. Now you will be able to see view the generated API endpoint and sample payload.

</details>

The following illustrations demonstrate three types of API payloads, helping you understand how to structure payloads for any template message.

<details>

<summary>Static Media Message with Dynamic Variables</summary>

```
Template Name :  Static Media Message with Dynamic Variables

Payload :  
{
  "receiver": "customer_mobile_number",
  "values": {
    "1": "custom_value",
    "2": "custom_value",
    "3": "custom_value"
  }
}

Webhook-Url :  "https://adminapis.backendprod.com/lms_campaign/api/whatsapp/template/20jpylrv97/process"
```

Webhook URL is the endpoint to which you have to submit the request.

In payload pass recipient number against key **“receiver”.**

Receiver Number format : \<countrycode>\<mobile number>\
Example : +917411223344\
\
Pass String values against dynamic variable “1”, “2”, “3”

</details>

<details>

<summary>Dynamic Media</summary>

```
Template Name :Dynamic Media

Payload :
{
  "receiver": "customer_mobile_number",
  "media_url": "media_url"
}
Webhook-Url :
"https://adminapis.backendprod.com/lms_campaign/api/whatsapp/template/uiw91c2k97/process
```

The medial URL should be public and secure.\
\
Supported Media Types : [https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media/#supported-media-types\ <br>](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media/#supported-media-types)Example<br>

<https://static.remove.bg/sample-gallery/graphics/bird-thumbnail.jpg>

</details>

<details>

<summary>One of the CTA button has Dynamic URL</summary>

```
Template Name :  Dynamic URL

Payload :  
{
  "receiver": "customer_mobile_number",
  "values": {
    "1": "custom_value"
  },
  "media_url": "media_url"
}

Webhook-Url :  "https://adminapis.backendprod.com/lms_campaign/api/whatsapp/template/ayd4zf7t83/process"
```

When a template's CTA includes a dynamic URL, you must provide the string to append to the static portion of the URL. Pass this value in the same way as dynamic variables within the template message.

</details>

<details>

<summary>API responses and Error codes</summary>

When you submit a Send Template Message API request to the Emovur server, we validate, process, and forward the request to Meta. We then provide an acknowledgment based on Meta's response. Upon successful submission, you will receive a response message. See the sample below:

Response

```

{
  "messaging_product": "whatsapp",
  "contacts": [
    {
      "input": "<WHATSAPP_USER_PHONE_NUMBER>",
      "wa_id": "<WHATSAPP_USER_ID>"
    }
  ],
  "messages": [
    {
      "id": "<WHATSAPP_MESSAGE_ID>",
      "message_status": "<PACING_STATUS>"
    }
  ]
}

```

Sample Response

```

{
    "messaging_product": "whatsapp",
    "contacts": [
        {
            "input": "9693971669",
            "wa_id": "919693971669"
        }
    ],
    "messages": [
        {
            "id": "wamid.HBgMOTE5NjkzOTcxNjY5FQIAERgSM0ExQzBFMjY5NjVEM0Q3MzJGAA==",
            "message_status": "accepted"
        }
    ]
}

```

If the message submission fails, an error message and code will be returned. You can refer to the [Error Codes Documentation ](https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes)for detailed information on specific errors.

</details>

If the submission to the Emovur server is invalid or contains missing parameters, an error message will be returned as shown below.

<table><thead><tr><th width="345"> Error Message</th><th> Description</th></tr></thead><tbody><tr><td>The receiver field is required</td><td><p>Number format : &#x3C;countrycode>&#x3C;mobile number><br><br>Example:</p><p>Country code : +91<br>Mobile Number : 7411223344<br>Should be structured as +917411223344</p></td></tr><tr><td>The media url field is required</td><td>The medial URL should be public and secure<br><br>Supported Media Types : <a href="https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media/#supported-media-types">https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media/#supported-media-types<br><br></a>Example<br><a href="https://static.remove.bg/sample-gallery/graphics/bird-thumbnail.jpg">https://static.remove.bg/sample-gallery/graphics/bird-thumbnail.jpg</a></td></tr><tr><td>The values.n field is required</td><td>The value for dynamic variables in the message body or for the dynamic URL is missing.</td></tr></tbody></table>
