### Fetch Filtered Message Logs (Go) Source: https://kirem.co/docs/pull-message-logs Use Go's standard `net/http` package to perform a GET request. Set the Authorization header and include query parameters directly in the URL for filtering and limiting results. The example prints the HTTP status of the response. ```go package main import ( "fmt" "net/http" ) func main() { url := "https://api.kirem.co/v1/analytics/messages?status=failed&limit=20" req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Authorization", "Bearer kirem_live_xxx") client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() fmt.Println("Status:", resp.Status) } ``` -------------------------------- ### List Available Kirem MCP Tools Source: https://kirem.co/docs/mcp Use this method to get a schema and a complete list of tools supported by Kirem. This is the first step to understand available functionalities. ```json { "jsonrpc": "2.0", "method": "tools/list", "id": 1 } ``` ```json { "jsonrpc": "2.0", "result": { "tools": [ { "name": "send_message", "description": "Kirim pesan WhatsApp ke session chat/percakapan tertentu.", "inputSchema": { "type": "object", "properties": { "session_id": { "type": "string", "description": "ID dari chat session/percakapan." }, "text": { "type": "string", "description": "Isi pesan teks yang ingin dikirim." } }, "required": ["session_id", "text"] } }, { "name": "list_conversations", "description": "Dapatkan daftar percakapan (chat sessions) aktif dalam proyek.", "inputSchema": { "type": "object", "properties": { "status": { "type": "string", "description": "Saring berdasarkan status percakapan (open, pending, resolved, on_hold). Opsional." } } } }, { "name": "get_conversation", "description": "Dapatkan detail percakapan (chat session) beserta riwayat timeline pesannya.", "inputSchema": { "type": "object", "properties": { "session_id": { "type": "string", "description": "ID dari chat session/percakapan." } }, "required": ["session_id"] } } ] }, "id": 1 } ``` -------------------------------- ### Mengambil Daftar Templat Pesan Source: https://kirem.co/docs/list-templates Gunakan cURL untuk melakukan permintaan GET ke endpoint /v1/templates guna mengambil daftar semua templat pesan WhatsApp. Pastikan untuk menyertakan header Authorization. ```bash curl -X GET "https://api.kirem.co/v1/templates" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Mengambil Daftar Templat Pesan dengan Go Source: https://kirem.co/docs/list-templates Contoh Go untuk melakukan permintaan GET ke endpoint /v1/templates. Kode ini mencetak status respons HTTP. Pastikan untuk menyertakan header Authorization. ```go package main import ( "fmt" "net/http" ) func main() { req, _ := http.NewRequest("GET", "https://api.kirem.co/v1/templates", nil) req.Header.Set("Authorization", "Bearer kirem_live_xxx") client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() fmt.Println("Status:", resp.Status) } ``` -------------------------------- ### Meta Cloud API Error Handling Example (400 Bad Request) Source: https://kirem.co/docs/response-wrapper This example shows how Kirem wraps specific errors from the Meta WhatsApp Cloud API within the standard error response. This is useful for diagnosing issues like unapproved message templates. ```json { "status": 400, "message": "( #132000) Template status is not APPROVED.", "errors": { "message": "( #132000) Template status is not APPROVED.", "type": "OAuthException", "code": 132000, "error_subcode": 2490001 } } ``` -------------------------------- ### Send Interactive Message - Quick Reply Buttons Source: https://kirem.co/docs/send-interactive This example demonstrates how to send a message with Quick Reply Buttons. Up to three buttons can be displayed below the chat message bubble, allowing users to interact easily without manual typing. ```APIDOC ## POST /v1/messages ### Description Sends an interactive message with Quick Reply Buttons. These buttons provide quick response options for users. ### Method POST ### Endpoint `/v1/messages` or `/v1/:phone_number_id/messages` ### Headers: - `Authorization`: `Bearer ` - `Content-Type`: `application/json` ### Request Body ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "interactive", "interactive": { "type": "button", "header": { "type": "text", "text": "Konfirmasi Pendaftaran" }, "body": { "text": "Apakah Anda bersedia melanjutkan pendaftaran?" }, "footer": { "text": "Layanan Pendaftaran Otomatis" }, "action": { "buttons": [ { "type": "reply", "reply": { "id": "btn_yes", "title": "Ya, bersedia" } }, { "type": "reply", "reply": { "id": "btn_no", "title": "Tidak, batalkan" } } ] } } } ``` ### Response (Success response details not provided in source) ``` -------------------------------- ### Fetch Failed Webhook Logs (Go) Source: https://kirem.co/docs/pull-webhook-logs Fetch failed webhook logs in Go using the net/http package. This example demonstrates setting the Authorization header and query parameters for filtering and limiting results. ```go package main import ( "fmt" "net/http" ) func main() { url := "https://api.kirem.co/v1/analytics/webhooks?is_success=false&limit=10" req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Authorization", "Bearer kirem_live_xxx") client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() fmt.Println("Status:", resp.Status) } ``` -------------------------------- ### GET /v1/profile Source: https://kirem.co/docs/get-profile Endpoint ini mengambil informasi detail profil bisnis WhatsApp yang saat ini terdaftar di Meta. Gunakan endpoint ini untuk memverifikasi data profil sebelum melakukan pembaruan, atau untuk menampilkan informasi bisnis di aplikasi Anda. ```APIDOC ## GET /v1/profile ### Description Mengambil informasi detail profil bisnis WhatsApp yang terdaftar di Meta. ### Method GET ### Endpoint /v1/profile ### Parameters Endpoint ini tidak memerlukan parameter tambahan. Cukup sertakan header `Authorization`. ### Request Example ```curl curl -X GET "https://api.kirem.co/v1/profile" \ -H "Authorization: Bearer kirem_live_xxx" ``` ### Response #### Success Response (200 OK) - **about** (string) - Informasi singkat tentang bisnis Anda (ditampilkan di bawah nama bisnis) - **address** (string) - Alamat fisik bisnis yang tercantum di profil - **description** (string) - Deskripsi panjang bisnis Anda - **email** (string) - Alamat email kontak resmi bisnis - **vertical** (string) - Kategori industri bisnis Anda (contoh: `RETAIL`, `FINANCE`, `HEALTH`) - **websites** (array of strings) - Daftar situs web resmi (maksimal 2 tautan) - **profile_picture_url** (string) - URL gambar profil WhatsApp Business Anda #### Response Example ```json { "status": 200, "message": "Business profile retrieved successfully", "data": { "about": "Solusi Komunikasi Bisnis Terbaik", "address": "Gedung Cyber 2, Lt. 15, Jakarta Selatan", "description": "Kirem adalah platform WhatsApp Business API Developer Terpercaya.", "email": "support@kirem.co.id", "vertical": "RETAIL", "websites": [ "https://kirem.co.id", "https://docs.kirem.co.id" ], "profile_picture_url": "https://pps.whatsapp.net/v/t61.24694-24/..." } } ``` ``` -------------------------------- ### Send First Message Source: https://kirem.co/docs/quickstart This example demonstrates how to send your first message using the Kirem API via cURL. It includes the necessary endpoint, headers, and request body structure. ```APIDOC ## POST /v1/messages ### Description Send your first message using the Kirem API. ### Method POST ### Endpoint /v1/messages ### Request Body - **messaging_product** (string) - Required - Specifies the messaging product, e.g., "whatsapp". - **recipient_type** (string) - Required - Specifies the recipient type, e.g., "individual". - **to** (string) - Required - The recipient's phone number. - **type** (string) - Required - The type of message, e.g., "text". - **text** (object) - Required - Contains the text message content. - **body** (string) - Required - The body of the text message. ### Request Example ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "text", "text": { "body": "Halo! Ini adalah pesan uji coba pertama saya menggunakan Kirem API." } } ``` ### Response #### Success Response (201 Created) Indicates that the message was successfully sent. ``` -------------------------------- ### Send Interactive Message - List Messages Source: https://kirem.co/docs/send-interactive This example shows how to send a message with a List Menu. This feature allows for organized menu options, with up to 10 selectable rows within a dropdown button. ```APIDOC ## POST /v1/messages ### Description Sends an interactive message with a List Menu. This allows users to select from a list of predefined options presented in a dropdown. ### Method POST ### Endpoint `/v1/messages` or `/v1/:phone_number_id/messages` ### Headers: - `Authorization`: `Bearer ` - `Content-Type`: `application/json` ### Request Body ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "interactive", "interactive": { "type": "list", "header": { "type": "text", "text": "Pusat Layanan Kirem" }, "body": { "text": "Silakan pilih menu bantuan di bawah ini untuk memulai interaksi." }, "footer": { "text": "Kirem Bot Service" }, "action": { "button": "Pilih Bantuan", "sections": [ { "title": "Layanan Umum", "rows": [ { "id": "menu_billing", "title": "Cek Tagihan", "description": "Melihat rincian tagihan bulanan Anda" }, { "id": "menu_support", "title": "Hubungi Support", "description": "Hubungkan dengan tim developer support" } ] }, { "title": "Layanan Teknis", "rows": [ { "id": "menu_webhook_test", "title": "Uji Webhook", "description": "Kirim payload testing ke server Anda" } ] } ] } } } ``` ### Response (Success response details not provided in source) ``` -------------------------------- ### Mengambil Daftar Templat Pesan dengan Node.js Source: https://kirem.co/docs/list-templates Menggunakan pustaka axios di Node.js untuk melakukan permintaan GET ke endpoint /v1/templates. Respons data akan dicetak ke konsol. Pastikan untuk menyertakan header Authorization. ```javascript const axios = require('axios'); axios.get('https://api.kirem.co/v1/templates', { headers: { 'Authorization': 'Bearer kirem_live_xxx' } }).then(res => console.log(res.data)); ``` -------------------------------- ### Mengambil Daftar Templat Pesan dengan PHP Source: https://kirem.co/docs/list-templates Contoh PHP menggunakan cURL untuk melakukan permintaan GET ke endpoint /v1/templates. Respons akan dicetak ke output. Pastikan untuk menyertakan header Authorization. ```php { const { total, logs } = res.data.data; console.log(`Total webhook gagal: ${total}`); logs.forEach(log => { console.log(`${log.url} — HTTP ${log.status_code} (${log.duration_ms}ms)`); }); }); ``` -------------------------------- ### Paginate Message Logs Source: https://kirem.co/docs/pull-message-logs Use `limit` and `offset` parameters to navigate through large result sets. `data.total` shows the total matching records, `data.limit` is the records per page, and `data.offset` is the current page's starting position. ```http # Halaman 1: 50 catatan pertama GET /v1/analytics/messages?limit=50&offset=0 # Halaman 2: 50 catatan berikutnya GET /v1/analytics/messages?limit=50&offset=50 # Halaman 3 GET /v1/analytics/messages?limit=50&offset=100 ``` -------------------------------- ### Contoh Kode (Go — io.Copy ke file) Source: https://kirem.co/docs/download-media Mengunduh file media di Go dan menyimpannya ke file lokal menggunakan io.Copy. Pastikan untuk menangani error dengan benar dalam implementasi produksi. ```go package main import ( "fmt" "io" "net/http" "os" ) func main() { url := "https://api.kirem.co/v1/media/18471948194819/download" req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Authorization", "Bearer kirem_live_xxx") client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() file, _ := os.Create("downloaded_image.png") defer file.Close() io.Copy(file, resp.Body) fmt.Println("File berhasil disimpan!") } ``` -------------------------------- ### Node.js Request to Get WhatsApp Business Profile Source: https://kirem.co/docs/get-profile This Node.js snippet uses the axios library to make a GET request to retrieve WhatsApp Business profile information. It includes the necessary Authorization header. ```javascript const axios = require('axios'); axios.get('https://api.kirem.co/v1/profile', { headers: { 'Authorization': 'Bearer kirem_live_xxx' } }).then(res => console.log(res.data)); ``` -------------------------------- ### Menghapus Templat Pesan dengan Go Source: https://kirem.co/docs/delete-template Implementasi penghapusan templat pesan WhatsApp menggunakan Go. Nama templat di-URL encode menggunakan url.PathEscape sebelum dimasukkan ke dalam URL permintaan. ```go package main import ( "fmt" "net/http" "net/url" ) func main() { templateName := "promo_diskon_baru" encodedName := url.PathEscape(templateName) req, _ := http.NewRequest("DELETE", fmt.Sprintf("https://api.kirem.co/v1/templates/%s", encodedName), nil) req.Header.Set("Authorization", "Bearer kirem_live_xxx") client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() fmt.Println("Status:", resp.Status) } ``` -------------------------------- ### GET /v1/analytics/messages Source: https://kirem.co/docs/pull-message-logs Retrieves message logs. Supports pagination using `limit` and `offset` query parameters. Can also filter by `status` and `direction`. ```APIDOC ## GET /v1/analytics/messages ### Description Retrieves message logs. Supports pagination using `limit` and `offset` query parameters. Can also filter by `status` and `direction`. ### Method GET ### Endpoint /v1/analytics/messages ### Parameters #### Query Parameters - **limit** (integer) - Optional - The number of records to return per page. - **offset** (integer) - Optional - The starting position for the current page of results. - **status** (string) - Optional - Filters logs by their status (e.g., 'failed'). - **direction** (string) - Optional - Filters logs by their direction (e.g., 'outbound'). ### Response #### Success Response (200) - **data.total** (integer) - The total number of records matching the filter. - **data.limit** (integer) - The number of records per page. - **data.offset** (integer) - The starting position of the current page. - **data.logs** (array) - An array of log objects. ``` -------------------------------- ### Get Specific Conversation Details Source: https://kirem.co/docs/mcp Fetch the complete message history for a given conversation session to provide context. The `session_id` must be a valid UUID. ```json { "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "get_conversation", "arguments": { "session_id": "8a3d12d4-1a9b-4bfa-a7b3-c123456789ab" // Wajib berupa UUID session yang valid } }, "id": 3 } ``` ```json { "jsonrpc": "2.0", "result": { "content": [ { "type": "text", "text": "{"session":{"id":"8a3d12d4-1a9b-4bfa-a7b3-c123456789ab","status":"open"},"messages":[{"id":"msg_1","sender":"customer","text":"Halo, apakah produk X ready?","created_at":"..."}]}" } ] }, "id": 3 } ``` -------------------------------- ### Memfilter Templat Pesan Berdasarkan Status (Menunggu) Source: https://kirem.co/docs/list-templates Gunakan parameter query 'status=PENDING' untuk memfilter dan hanya menampilkan templat pesan WhatsApp yang sedang dalam proses peninjauan oleh Meta. Sertakan header Authorization. ```bash # Hanya tampilkan templat yang masih menunggu curl -X GET "https://api.kirem.co/v1/templates?status=PENDING" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Memfilter Templat Pesan Berdasarkan Status (Disetujui) Source: https://kirem.co/docs/list-templates Gunakan parameter query 'status=APPROVED' untuk memfilter dan hanya menampilkan templat pesan WhatsApp yang telah disetujui oleh Meta. Sertakan header Authorization. ```bash # Hanya tampilkan templat yang sudah disetujui curl -X GET "https://api.kirem.co/v1/templates?status=APPROVED" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Successful Response (200 OK) for Business Profile Source: https://kirem.co/docs/get-profile This is an example of a successful response when retrieving a WhatsApp Business profile. It includes status, message, and detailed business data. ```json { "status": 200, "message": "Business profile retrieved successfully", "data": { "about": "Solusi Komunikasi Bisnis Terbaik", "address": "Gedung Cyber 2, Lt. 15, Jakarta Selatan", "description": "Kirem adalah platform WhatsApp Business API Developer Terpercaya.", "email": "support@kirem.co.id", "vertical": "RETAIL", "websites": [ "https://kirem.co.id", "https://docs.kirem.co.id" ], "profile_picture_url": "https://pps.whatsapp.net/v/t61.24694-24/..." } } ``` -------------------------------- ### Get Conversation History Source: https://kirem.co/docs/mcp Fetches the detailed message history for a specific conversation identified by its session ID. This allows the AI agent to understand the context of the customer's query. ```APIDOC ## POST /v1/mcp ### Description Fetches the detailed message history for a specific conversation. ### Method POST ### Endpoint /v1/mcp ### Parameters #### Request Body - **method** (string) - Required - The tool to call, should be 'tools/call'. - **tool** (string) - Required - The specific tool to use, should be 'get_conversation'. - **session_id** (string) - Required - The unique identifier (UUID) of the conversation session. ``` -------------------------------- ### PHP Request to Get WhatsApp Business Profile Source: https://kirem.co/docs/get-profile This PHP script uses cURL to request WhatsApp Business profile information. It sets the Authorization header and retrieves the response. ```php console.log(res.data)); ``` -------------------------------- ### cURL Request to Get WhatsApp Business Profile Source: https://kirem.co/docs/get-profile Use this cURL command to fetch the details of a WhatsApp Business profile. Ensure you include the Authorization header with your bearer token. ```bash curl -X GET "https://api.kirem.co/v1/profile" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Mengirim Pesan Templat (Template) Source: https://kirem.co/docs/send-template Endpoint ini digunakan untuk mengirimkan pesan menggunakan templat pesan yang telah didaftarkan dan disetujui oleh Meta. Templat pesan wajib digunakan untuk membuka sesi obrolan baru dengan pelanggan jika di luar jendela interaksi 24 jam. ```APIDOC ## POST /v1/messages ### Description Endpoint ini digunakan untuk mengirimkan pesan menggunakan templat pesan (_Message Template_) yang telah didaftarkan dan disetujui (_APPROVED_) oleh Meta. Templat pesan wajib digunakan untuk membuka sesi obrolan baru dengan pelanggan jika di luar jendela interaksi 24 jam. ### Method POST ### Endpoint - `POST /v1/messages` (Routing otomatis menggunakan saluran aktif pertama) - `POST /v1/:phone_number_id/messages` (Routing melalui nomor tertentu) ### Headers - `Authorization: Bearer ` - `Content-Type: application/json ### Request Body ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "template", "template": { "name": "promo_diskon_baru", "language": { "code": "id" }, "components": [ { "type": "header", "parameters": [ { "type": "text", "text": "Budi" } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "50" }, { "type": "text", "text": "HEMAT50" } ] } ] } } ``` ### Parameters #### Request Body Fields - `messaging_product` (String - Wajib): Produk pengiriman pesan, contoh: `"whatsapp"`. - `recipient_type` (String - Wajib): Tipe penerima, contoh: `"individual"`. - `to` (String - Wajib): Nomor telepon penerima. - `type` (String - Wajib): Tipe pesan, harus `"template"`. - `template` (Object - Wajib): Objek yang berisi detail templat pesan. - `name` (String - Wajib): Nama unik templat pesan yang sudah disetujui Meta. - `language` (Object - Wajib): Objek yang berisi kode bahasa templat. - `code` (String - Wajib): Kode bahasa templat (misal: `"id"` untuk Bahasa Indonesia, `"en"` untuk Bahasa Inggris). - `components` (Array - Opsional): Kumpulan komponen yang mendefinisikan nilai variabel dinamis pada templat. - `type` (String - Wajib): Jenis komponen (`header`, `body`, `button`). - `parameters` (Array - Wajib): Array nilai parameter yang disubstitusikan ke dalam variabel secara berurutan. - `type` (String - Wajib): Tipe parameter (`text`, `currency`, `date_time`, `image`, `document`, `video`). - `text` (String - Wajib): Isi nilai teks pengganti jika tipe parameter adalah `"text"`. ### Response #### Success Response (201 Created) ```json { "status": 201, "message": "Message sent successfully", "data": { "messaging_product": "whatsapp", "contacts": [ { "input": "62812345678", "wa_id": "62812345678" } ], "messages": [ { "id": "wamid.HBgLNjI4MTIzNDU2NzhGFgQ0NDMzMzc3RUQ1OEFG" } ] } } ``` #### Response Fields - `status` (Integer): Kode status respons HTTP. - `message` (String): Pesan status pengiriman. - `data` (Object): Objek berisi detail pengiriman pesan. - `messaging_product` (String): Produk pengiriman pesan. - `contacts` (Array): Array informasi kontak penerima. - `input` (String): Input nomor telepon penerima. - `wa_id` (String): WhatsApp ID penerima. - `messages` (Array): Array informasi pesan yang dikirim. - `id` (String): ID pesan untuk memantau status pengantaran via webhook callback. ``` -------------------------------- ### cURL Request: Inbound Messages Source: https://kirem.co/docs/pull-message-logs Use this cURL command to retrieve inbound messages. It filters by 'inbound' direction, sets the limit to 50, and starts from the first record (offset 0). ```bash curl -X GET "https://api.kirem.co/v1/analytics/messages?direction=inbound&limit=50&offset=0" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Go Request to Get WhatsApp Business Profile Source: https://kirem.co/docs/get-profile A Go program to fetch WhatsApp Business profile details using the standard net/http package. It sets the Authorization header before making the request. ```go package main import ( "fmt" "net/http" ) func main() { req, _ := http.NewRequest("GET", "https://api.kirem.co/v1/profile", nil) req.Header.Set("Authorization", "Bearer kirem_live_xxx") client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() fmt.Println("Status:", resp.Status) } ``` -------------------------------- ### Contoh cURL Request (simpan ke file) Source: https://kirem.co/docs/download-media Gunakan perintah cURL untuk mengunduh file media dan menyimpannya ke file lokal. Pastikan untuk mengganti placeholder media_id dan token otorisasi. ```bash curl -X GET "https://api.kirem.co/v1/media/18471948194819/download" \ -H "Authorization: Bearer kirem_live_xxx" \ --output downloaded_image.png ``` -------------------------------- ### ngrok command for local development Source: https://kirem.co/docs/n8n-whatsapp-bot Use ngrok to expose your local development server to the internet, making your n8n webhook accessible. ```bash ngrok http 5678 ``` -------------------------------- ### Contoh Kode (Node.js — stream ke file) Source: https://kirem.co/docs/download-media Mengunduh file media menggunakan Axios di Node.js dan menyimpannya ke file lokal menggunakan stream. Pastikan untuk menginstal pustaka 'axios' dan 'fs' sudah tersedia. ```javascript const axios = require('axios'); const fs = require('fs'); axios.get('https://api.kirem.co/v1/media/18471948194819/download', { headers: { 'Authorization': 'Bearer kirem_live_xxx' }, responseType: 'stream' }).then(res => { res.data.pipe(fs.createWriteStream('downloaded_image.png')); console.log('File berhasil disimpan!'); }); ``` -------------------------------- ### Kirem Node - Send Welcome Reply Source: https://kirem.co/docs/n8n-whatsapp-bot Configure the Kirem node to send a welcome message. Set the Resource to 'Message', Operation to 'Send', and provide the Phone Number ID. The 'To' field should dynamically capture the sender's number, and the 'Body' contains the welcome text. ```text Resource : Message Operation : Send Phone Number ID : (ID nomor WhatsApp Anda dari Dasbor Kirem) To : {{ $json.body.entry[0].changes[0].value.messages[0].from }} Message Type : Text Body : Halo! 👋 Selamat datang di layanan kami. Berikut yang bisa saya bantu: - Ketik *Harga* untuk info produk & harga - Ketik *Bantuan* untuk bantuan pelanggan - Ketik *Jam* untuk jam operasional ``` -------------------------------- ### Mengirim Pesan Video via Endpoint Source: https://kirem.co/docs/send-video Endpoint ini digunakan untuk mengirimkan berkas video (MP4/3GP) ke pelanggan. Mendukung pengiriman menggunakan Media ID Meta atau Tautan URL video eksternal. ```APIDOC ## POST /v1/messages ### Description Endpoint ini digunakan untuk mengirimkan berkas video (MP4/3GP) ke pelanggan. Layaknya gambar, pengiriman video mendukung dua metode: menggunakan **Media ID** Meta atau menggunakan **Tautan URL** video eksternal secara langsung. ### Method POST ### Endpoint - `POST /v1/messages` (Routing otomatis menggunakan saluran aktif pertama) - `POST /v1/:phone_number_id/messages` (Routing melalui nomor tertentu) ### Headers - `Authorization: Bearer ` - `Content-Type: application/json` ### Request Body #### Metode A: Menggunakan Media ID (Direkomendasikan) ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "video", "video": { "id": "18471948194820", "caption": "Silakan tonton video demo produk kami" } } ``` #### Metode B: Menggunakan Tautan URL Langsung ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "video", "video": { "link": "https://kirem.id/assets/demo-video.mp4", "caption": "Video Tutorial Penggunaan Kirem API" } } ``` ### Parameters #### Request Body Parameters - `type` (String - Wajib): Set nilai ke `"video"`. - `video.id` (String - Wajib jika tidak memakai link): ID media video hasil unggahan. - `video.link` (String - Wajib jika tidak memakai ID): Tautan HTTPS langsung ke file video (harus berakhiran format video, misal `.mp4`/`.3gp`). - `video.caption` (String - Opsional): Teks keterangan yang disematkan tepat di bawah pratinjau video di aplikasi pelanggan. ### Response #### Success Response (201 Created) ```json { "status": 201, "message": "Message sent successfully", "data": { "messaging_product": "whatsapp", "contacts": [{"input": "62812345678", "wa_id": "62812345678"}], "messages": [{"id": "wamid.HBgLNjI4MTIzNDU2NzhGFgQ0NDMzMzc3RUQ1OEFG"}] } } ``` - `messages[0].id`: ID pesan unik untuk melacak status pengantaran via webhook. ``` -------------------------------- ### Switch Node Configuration for Keyword Matching Source: https://kirem.co/docs/n8n-whatsapp-bot Set up a Switch node to route messages based on keywords. Use the message body as input and define rules for matching specific terms like 'Harga', 'Bantuan', or 'Jam' to different outputs. ```text Mode : Rules Input : {{ $json.body.entry[0].changes[0].value.messages[0].text.body }} Aturan | Operator | Nilai | Output ---|---|---|--- `contains` | Halo | 1 (Sambutan) | `contains` | Hai | 1 (Sambutan) | `contains` or `matches` | Harga | 2 (Harga) | `contains` or `matches` | Bantuan | 3 (Bantuan) | `contains` or `matches` | Jam | 4 (Jam Operasional) | ``` -------------------------------- ### Membuat Templat Pesan Notifikasi Pesanan Source: https://kirem.co/docs/woocommerce-order-notif Gunakan endpoint POST /v1/templates untuk membuat templat pesan WhatsApp yang akan digunakan untuk notifikasi pesanan baru. Pastikan templat disetujui sebelum melanjutkan. ```json { "name": "notif_pesanan_baru", "category": "UTILITY", "language": "id", "components": [ { "type": "BODY", "text": "Halo {{1}}, terima kasih telah berbelanja di {{2}}!\n\nPesanan #{{3}} telah kami terima.\nTotal: Rp {{4}}\n\nKami akan segera memproses pesanan Anda." } ] } ``` -------------------------------- ### Menghapus Templat Pesan dengan cURL Source: https://kirem.co/docs/delete-template Contoh penggunaan cURL untuk menghapus templat pesan WhatsApp. Pastikan untuk menyertakan nama templat yang sudah di-URL encoding pada path dan header Authorization. ```bash curl -X DELETE "https://api.kirem.co/v1/templates/promo_diskon_baru" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Mengambil Informasi Profil Bisnis Source: https://kirem.co/docs/manage-profile Gunakan contoh cURL ini untuk mengambil detail profil bisnis WhatsApp yang terdaftar di Meta. Pastikan Anda menyertakan channel_id yang valid. ```bash curl -X GET "https://api.kirem.id/v1/profile?channel_id=chan-123" \ -H "Authorization: Bearer kirem_live_xxx" ``` -------------------------------- ### Fetch Filtered Message Logs (PHP) Source: https://kirem.co/docs/pull-message-logs Utilize cURL in PHP to make a GET request to the messages endpoint. Set the Authorization header and append query parameters for filtering and limiting. The response is decoded from JSON, and the total count and logs are printed. ```php get_items(); $product_list = ''; foreach ($items as $item) { $product_name = $item->get_name(); $quantity = $item->get_quantity(); $product_list .= "- {$product_name} x{$quantity}\n"; } // Tambahkan parameter ke-5: ['type' => 'text', 'text' => $product_list], ``` -------------------------------- ### Fetch Filtered Message Logs (Node.js) Source: https://kirem.co/docs/pull-message-logs Use the Axios library to make a GET request to the messages endpoint. Include an Authorization header and specify query parameters for filtering and pagination. The response includes total logs, count of logs in the current response, and the logs themselves. ```javascript const axios = require('axios'); axios.get('https://api.kirem.co/v1/analytics/messages', { headers: { 'Authorization': 'Bearer kirem_live_xxx' }, params: { status: 'failed', direction: 'outbound', limit: 20 } }).then(res => { console.log(`Total: ${res.data.data.total}`); console.log(`Logs: ${res.data.data.logs.length}`); console.log(res.data.data.logs); }); ``` -------------------------------- ### Mengirim Pesan Gambar via Endpoint Source: https://kirem.co/docs/send-image Endpoint ini digunakan untuk mengirimkan berkas gambar (JPEG/PNG) ke pelanggan. WhatsApp mendukung dua metode pengiriman gambar: menggunakan Media ID (berkas yang telah diunggah sebelumnya di server Meta) atau menggunakan Tautan URL gambar eksternal secara langsung. ```APIDOC ## POST /v1/messages atau POST /v1/:phone_number_id/messages ### Description Endpoint ini digunakan untuk mengirimkan berkas gambar (JPEG/PNG) ke pelanggan. WhatsApp mendukung dua metode pengiriman gambar: menggunakan **Media ID** (berkas yang telah diunggah sebelumnya di server Meta) atau menggunakan **Tautan URL** gambar eksternal secara langsung. ### Method POST ### Endpoint - `POST /v1/messages` (Routing otomatis menggunakan saluran aktif pertama) - `POST /v1/:phone_number_id/messages` (Routing melalui nomor tertentu) ### Headers - `Authorization: Bearer ` - `Content-Type: application/json` ### Request Body #### Metode A: Menggunakan Media ID (Direkomendasikan) ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "image", "image": { "id": "18471948194819", "caption": "Silakan lihat gambar brosur promo kami" } } ``` #### Metode B: Menggunakan Tautan URL Langsung ```json { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "62812345678", "type": "image", "image": { "link": "https://kirem.id/assets/promo-poster.png", "caption": "Brosur Promo Akhir Tahun Kirem" } } ``` ### Parameters - `type` (String - Wajib): Set nilai ke "image". - `image.id` (String - Wajib jika tidak memakai link): ID media gambar hasil unggahan. - `image.link` (String - Wajib jika tidak memakai ID): Tautan HTTPS langsung ke file gambar yang dihosting di server Anda (harus berakhiran format gambar, misal `.jpg`/`.png`). - `image.caption` (String - Opsional): Teks keterangan yang disematkan tepat di bawah pratinjau gambar di aplikasi pelanggan. ### Response #### Success Response (201 Created) ```json { "status": 201, "message": "Message sent successfully", "data": { "messaging_product": "whatsapp", "contacts": [{"input": "62812345678", "wa_id": "62812345678"}], "messages": [{"id": "wamid.HBgLNjI4MTIzNDU2NzhGFgQ0NDMzMzc3RUQ1OEFG"}] } } ``` **Note**: Meta membatasi ukuran file gambar maksimal sebesar 5 MB dengan format file yang didukung adalah `image/jpeg` dan `image/png`. ``` -------------------------------- ### Webhook Configuration in n8n Source: https://kirem.co/docs/n8n-whatsapp-bot Configure the Webhook node in n8n to receive incoming messages. Ensure the HTTP Method is POST, set a Path, and select 'Last Node' for Response Mode with 'All Entries' for Response Data. Execute the node to get the Production URL. ```text HTTP Method : POST Path : /whatsapp-bot Response Mode : Last Node Response Data : All Entries ``` -------------------------------- ### Menghapus Templat Pesan Source: https://kirem.co/docs/delete-template Endpoint ini menghapus templat pesan WhatsApp yang sudah terdaftar dari sistem Meta. Penghapusan bersifat permanen dan tidak dapat dikembalikan. ```APIDOC ## DELETE /v1/templates/:name ### Description Endpoint ini menghapus templat pesan WhatsApp yang sudah terdaftar dari sistem Meta. Penghapusan bersifat permanen — templat yang telah dihapus **tidak dapat dikembalikan**. ### Method DELETE ### Endpoint `/v1/templates/:name` Parameter `:name` adalah nama templat yang akan dihapus. Jika nama mengandung karakter khusus, lakukan **URL encoding** (misalnya spasi menjadi `%20`). ### Parameters Endpoint ini **tidak memerlukan query parameter tambahan**. Cukup sertakan nama templat pada path URL dan header `Authorization`. ### Request Example ```curl curl -X DELETE "https://api.kirem.co/v1/templates/promo_diskon_baru" \ -H "Authorization: Bearer kirem_live_xxx" ``` ### Response #### Success Response (200 OK) - **status** (integer) - 200 - **message** (string) - Template deleted successfully - **data** (object) - **success** (boolean) - true #### Response Example ```json { "status": 200, "message": "Template deleted successfully", "data": { "success": true } } ``` #### Error Response - **404 Not Found**: Jika nama templat tidak ditemukan. ```