Conversation API

Overview

Unifonic provides APIs that allow you to send WhatsApp messages, including templates with dynamic content, media attachments, product catalogs, and session messages. The API supports various types of messages such as text, templates, product lists, OTPs, and more.

Base URL

All endpoints are accessible via the following base URL:

arduino
https://apis.unifonic.com/v1

Authentication

To interact with the API, you will need:

  • PublicId: Your unique public ID for authentication.
  • Secret: Your secret key used for signing requests.

You will need to pass these values in the request headers.

Headers

Each API request should include the following headers:

  • PublicId: Your unique public ID.
  • Secret: Your secret API key.
  • Content-Type: application/json

Example headers:

json
{ "PublicId": "your-public-id", "Secret": "your-secret-key", "Content-Type": "application/json" }

Endpoints

1. Send Multi-Product Message

Sends a WhatsApp message with a product catalog, which includes a header, body, footer, and product sections.

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "productList", "header": { "type": "text", "text": "Unifonic Demo T-Shirts" }, "body": "We have selected a few items that you might be interested in from the Unifonic catalog, you can view them below", "footer": { "text": "Unifonic Team" }, "catalogId": "{{catalogId}}", "sections": [ { "title": "Offers", "productItems": [ { "productRetailerId": "{{productId1}}" }, { "productRetailerId": "{{productId2}}" } ] }, { "title": "New Arrivals", "productItems": [ { "productRetailerId": "{{productId3}}" } ] } ] } }

2. Get Message Status

Retrieves the status of a sent message based on its messageId.

Endpoint:

bash
GET /messages/status

Parameters:

  • messageIds: A comma-separated list of message IDs for which you want the status.

Request URL Example:

bash
https://apis.unifonic.com/v1/messages/status?messageIds=6743a513-ece2-4d87-9c8c-599712f8e3c3

3. Send Template Message with Variables

Sends a template message with dynamic variables, such as names or amounts.

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "template", "name": "sandbox_account_update", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "Name" }, { "type": "text", "text": "Tester" }, { "type": "text", "text": "100 SAR" } ] } ] } }

4. Send Template Message with Image

Sends a template message that includes an image in the header.

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "template", "name": "sandbox_ticket_update", "language": { "code": "en" }, "components": [ { "type": "header", "parameters": [ { "type": "image", "url": "https://www.unifonic.com/hubfs/PressRelease_CBM.png" } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "Spider Man" }, { "type": "text", "text": "1 Jan" }, { "type": "text", "text": "ABC Cinema" } ] } ] } }

5. Send Template Message with Quick Reply Buttons

Sends a template message with quick reply buttons (e.g., "Attending", "Not Attending").

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "template", "name": "sandbox_appointment_update", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "Name" }, { "type": "text", "text": "1 Jan" }, { "type": "text", "text": "12:00 pm" } ] }, { "type": "options", "parameters": [ { "value": "Attending", "subType": "quickReply", "index": 0 }, { "value": "Not Attending", "subType": "quickReply", "index": 1 }, { "value": "Will Confirm later", "subType": "quickReply", "index": 2 } ] } ] } }

6. Send Template Message with PDF

Sends a template message with a PDF document in the header.

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "template", "name": "sandbox_reservation_update", "language": { "code": "en" }, "components": [ { "type": "header", "parameters": [ { "type": "file", "fileName": "Sample.pdf", "url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "Name" } ] } ] } }

7. Send Template Message with Call to Action

Sends a template message with a Call to Action (CTA).

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "template", "name": "sandbox_shipping_update", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "Name" } ] } ] } }

8. Send OTP Template

Sends an OTP (One Time Password) template message.

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "template", "name": "sandbox_otp", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "123456" } ] }, { "type": "options", "parameters": [ { "value": "123456", "subType": "url", "index": 0 } ] } ] } }

9. Send Session Message

Sends a simple WhatsApp message (e.g., a welcome message) within a session.

Endpoint:

bash
POST /messages

Request Body:

json
{ "recipient": { "contact": "{{phoneNumber}}", "channel": "whatsapp" }, "content": { "type": "text", "text": "Welcome to Unifonic" } }

Variables

The following variables should be provided in the request body or set in Postman:

VariableDescription
PublicIdYour public API key.
SecretYour secret API key.
phoneNumberThe recipient's phone number.
catalogIdThe ID of the product catalog.
productId1The ID of the first product.
productId2The ID of the second product.
productId3The ID of the third product.
urlFilePdfURL for a PDF file.
urlImagePngURL for a PNG image.
urlImageJpgURL for a JPG image.
urlVideoMp4URL for an MP4 video.
urlAudioMp3URL for an MP3 audio file.
mediaIdMedia ID for a sent file.

Error Handling

  • 400 Bad Request: Invalid request data, missing required fields, or incorrect format.
  • 401 Unauthorized: Invalid PublicId or Secret.
  • 404 Not Found: Endpoint not found.
  • 500 Internal Server Error: Server-side issues.