guides docs
guides docs

Apps Connection Guide

Complete guide to connecting your e-commerce apps with WhatAPI — from intro to live connection with code examples.

Apps Connection Guide

This guide covers everything you need to connect your e-commerce platform or custom application to WhatAPI for automated WhatsApp notifications.

1. Overview

WhatAPI acts as a bridge between your store/application and WhatsApp. When an event happens (new order, payment received, shipment), WhatAPI receives the data via webhook and sends a formatted WhatsApp message to your customer.

Flow:

Your App/Store → Webhook → WhatAPI Gateway → WhatsApp API → Customer's Phone

What You Need

  • A WhatAPI account with WhatsApp connected
  • Access to your app's webhook settings or REST API
  • Your WhatAPI User ID (found in Dashboard → Settings)

2. Connection Methods

Method A: Direct Platform Integration (No Code)

Supported platforms connect in one click:

PlatformMethodDifficulty
ShopifyOAuth / API Token / Native WebhooksEasy
WooCommerceConsumer Key + SecretEasy
Custom WebsiteREST API + Webhook URLMedium

Method B: REST API (For Developers)

Use the WhatAPI REST API to send messages programmatically.

Endpoint:

POST https://whatsapi.pk/api/v1/messages/send

Headers:

{
  "Content-Type": "application/json",
  "x-api-key": "YOUR_API_KEY"
}

Request Body:

{
  "phone": "+923001234567",
  "message": "Hello {customer_name}, your order #{order_number} has been confirmed!",
  "type": "text"
}

cURL Example:

curl -X POST "https://whatsapi.pk/api/v1/messages/send" \
  -H "Content-Type: application/json" \
  -H "x-api-key: your-api-key-here" \
  -d '{
    "phone": "+923001234567",
    "message": "Your order #1001 has been shipped! Track here: https://track.example.com/1001",
    "type": "text"
  }'

JavaScript (Node.js) Example:

const axios = require("axios");

async function sendWhatsAppMessage(phone, message) {
    const response = await axios.post(
        "https://whatsapi.pk/api/v1/messages/send",
        { phone, message, type: "text" },
        {
            headers: {
                "Content-Type": "application/json",
                "x-api-key": process.env.WHATAPI_API_KEY,
            },
        }
    );
    return response.data;
}

// Usage
sendWhatsAppMessage("+923001234567", "Your order #1001 is confirmed! 🎉")
    .then(console.log)
    .catch(console.error);

Python Example:

import requests

API_KEY = "your-api-key-here"
URL = "https://whatsapi.pk/api/v1/messages/send"

headers = {
    "Content-Type": "application/json",
    "x-api-key": API_KEY,
}

payload = {
    "phone": "+923001234567",
    "message": "Your order #1001 is confirmed! 🎉",
    "type": "text",
}

response = requests.post(URL, json=payload, headers=headers)
print(response.json())

3. Webhook Integration

For real-time notifications, configure webhooks in your app to send events to WhatAPI.

Webhook URL

https://whatsapi.pk/api/shopify/webhook?uid=YOUR_USER_ID

Replace `YOUR_USER_ID` with your actual user ID from the dashboard.

Supported Events

EventTriggerExample Use
orders/createNew order placedOrder confirmation message
orders/paidPayment receivedPayment receipt notification
fulfillments/createOrder shippedShipping update with tracking
orders/cancelledOrder cancelledCancellation notice
refunds/createRefund processedRefund confirmation

Webhook Payload Format

WhatAPI expects JSON payloads. Here's a minimal example:

{
  "id": 12345,
  "name": "#1001",
  "total_price": "2499.00",
  "currency": "PKR",
  "financial_status": "paid",
  "customer": {
    "first_name": "Ahmed",
    "phone": "+923001234567"
  },
  "line_items": [
    {
      "title": "Premium Leather Wallet",
      "quantity": 1
    }
  ],
  "shipping_address": {
    "city": "Islamabad",
    "address1": "Street 12, Sector F-11"
  }
}

4. Template Variables

When a webhook is received, you can use dynamic variables in your WhatsApp message templates:

Customer Variables

VariableSourceExample
{customer_name}customer.first_nameAhmed
{customer_phone}customer.phone+923001234567
{customer_address}shipping_address.address1Street 12, Sector F-11

Order Variables

VariableSourceExample
{order_number}name#1001
{order_total}total_price2499.00
{currency}currencyPKR
{payment_method}gatewayCash on Delivery
{items_list}line_itemsPremium Leather Wallet x1
{items_count}line_items.length2

Shipping Variables

VariableSourceExample
{shipping_city}shipping_address.cityIslamabad
{tracking_number}fulfillments[0].tracking_numberTRK-98765
{tracking_url}fulfillments[0].tracking_urlhttps://track.com/98765

5. Testing Your Connection

Test via Dashboard

  1. Go to **Connect Store** and select your platform.
  2. Click **Test Webhook** in the connection panel.
  3. Check your WhatsApp for the test message.

Test via cURL

curl -X POST "https://whatsapi.pk/api/shopify/webhook?uid=YOUR_USER_ID" \
  -H "Content-Type: application/json" \
  -H "x-shopify-topic: orders/create" \
  -d '{
    "id": 9999,
    "name": "#TEST-001",
    "total_price": "1500.00",
    "currency": "PKR",
    "customer": {
      "first_name": "Test",
      "phone": "+923001234567"
    },
    "line_items": [{"title": "Test Product", "quantity": 1}]
  }'

Verify Logs

In your dashboard, go to **Bulk Sender** or check the message logs to see delivery status.

6. Troubleshooting

IssueSolution
Webhook not triggeringVerify the URL is correct and includes `?uid=`
No WhatsApp messageConfirm WhatsApp is connected (`CONNECTED` status)
Invalid API keyRegenerate key in Settings → API Keys
Template shows raw variablesEnsure webhook payload includes the expected fields
Connection refusedCheck your store URL includes `https://`

7. Next Steps

Once connected:

  1. Customize Templates — Go to Templates to edit WhatsApp message formatting.
  2. Test Broadcasts — Use Bulk Sender to test message delivery.
  3. Monitor Analytics — Check the Dashboard for delivery rates and campaign stats.
  4. Explore API — Use our REST API for custom integrations.