Data Structures for WhatsApp API via OAuth 2.0

Prev Next

This article provides an overview of the data structures used in OAuth 2.0 message requests, focusing on how messages and templates are defined and structured.

Message Object

The primary object used to define the message content.

Type: template

This request is used for sending template messages. All templates must be pre-approved by Meta.

{
  "type": "template",
  "template": {
    "name": "welcome_message",
    "language": {
      "code": "tr"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Variable value"
          }
        ]
      }
    ]
  }
}

Type: text

This request is used to send plain-text messages.

{
  "type": "text",
  "text": {
    "body": "Hello! How can I help you?",
    "preview_url": false
  }
}

Type: image

This request is used to send images.

{
  "type": "image",
  "image": {
    "link": "https://example.com/image.jpg",
    "caption": "Image description"
  }
}

Or using an uploaded media ID:

{
  "type": "image",
  "image": {
    "id": "1234567890123456",
    "caption": "Image description"
  }
}

Type: video

This request is used to send videos.

{
  "type": "video",
  "video": {
    "link": "https://example.com/video.mp4",
    "caption": "Video description"
  }
}

Type: document

This request is used to send documents.

{
  "type": "document",
  "document": {
    "link": "https://example.com/document.pdf",
    "filename": "dokuman.pdf",
    "caption": "Document description"
  }
}

Type: audio

This request is used to send audio files.

{
  "type": "audio",
  "audio": {
    "link": "https://example.com/audio.mp3"
  }
}

Type: location

This request is used to send locations.

{
  "type": "location",
  "location": {
    "latitude": 41.0082,
    "longitude": 28.9784,
    "name": "Istanbul",
    "address": "Istanbul, Turkey"
  }
}

Type: interactive

This request is used to send interactive messages (buttons, lists).

{
  "type": "interactive",
  "interactive": {
    "type": "button",
    "body": {
      "text": "Which action would you like to take?"
    },
    "action": {
      "buttons": [
        {
          "type": "reply",
          "reply": {
            "id": "btn_1",
            "title": "Place Order"
          }
        },
        {
          "type": "reply",
          "reply": {
            "id": "btn_2",
            "title": "Get Support"
          }
        }
      ]
    }
  }
}

Template Components

The following component types are utilized within template messages:

Body Component

{
  "type": "body",
  "parameters": [
    {
      "type": "text",
      "text": "John Doe"
    }
  ]
}

Header Component

{
  "type": "header",
  "parameters": [
    {
      "type": "image",
      "image": {
        "link": "https://example.com/header-image.jpg"
      }
    }
  ]
}

Button Component

{
  "type": "button",
  "sub_type": "url",
  "index": "0",
  "parameters": [
    {
      "type": "text",
      "text": "PROMO2024"
    }
  ]
}

Carousel Component

{
  "type": "carousel",
  "cards": [
    {
      "card_index": 0,
      "components": [
        {
          "type": "header",
          "parameters": [
            {
              "type": "image",
              "image": {
                "link": "https://example.com/product1.jpg"
              }
            }
          ]
        },
        {
          "type": "body",
          "parameters": [
            {
              "type": "text",
              "text": "Product 1"
            }
          ]
        }
      ]
    }
  ]
}