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": "Değişken değer"
          }
        ]
      }
    ]
  }
}

Type: text

This request is used to send plain-text messages.

{
  "type": "text",
  "text": {
    "body": "Merhaba! Size nasıl yardımcı olabilirim?",
    "preview_url": false
  }
}

Type: image

This request is used to send images.

{
  "type": "image",
  "image": {
    "link": "https://example.com/image.jpg",
    "caption": "Resim açıklaması"
  }
}

Or using an uploaded media ID:

{
  "type": "image",
  "image": {
    "id": "1234567890123456",
    "caption": "Resim açıklaması"
  }
}

Type: video

This request is used to send videos.

{
  "type": "video",
  "video": {
    "link": "https://example.com/video.mp4",
    "caption": "Video açıklaması"
  }
}

Type: document

This request is used to send documents.

{
  "type": "document",
  "document": {
    "link": "https://example.com/document.pdf",
    "filename": "dokuman.pdf",
    "caption": "Döküman açıklaması"
  }
}

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": "İstanbul",
    "address": "İstanbul, Türkiye"
  }
}

Type: interactive

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

{
  "type": "interactive",
  "interactive": {
    "type": "button",
    "body": {
      "text": "Hangi işlemi yapmak istersiniz?"
    },
    "action": {
      "buttons": [
        {
          "type": "reply",
          "reply": {
            "id": "btn_1",
            "title": "Sipariş Ver"
          }
        },
        {
          "type": "reply",
          "reply": {
            "id": "btn_2",
            "title": "Destek Al"
          }
        }
      ]
    }
  }
}

Template Components

The following component types are utilized within template messages:

Body Component

{
  "type": "body",
  "parameters": [
    {
      "type": "text",
      "text": "Ahmet Yılmaz"
    }
  ]
}

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": "Ürün 1"
            }
          ]
        }
      ]
    }
  ]
}