WhatsApp API Integration Guide for Developers | Wavvy Blog
Back to Blog
API & Development December 2024 10 min read

WhatsApp API Integration Guide for Developers

Wavvy Team

WhatsApp Automation Experts

Got a website or app? Connect it to WhatsApp using Wavvy's API. Send order confirmations, payment receipts, delivery updates - all automatic.

This guide shows you exactly how. With code examples in Node.js, Python, and PHP.

Why Use WhatsApp API?

Customer places order on your website → API sends WhatsApp confirmation automatically. Payment received → API sends receipt. Order shipped → API sends tracking. All without you touching anything.

Real Example

Karachi online store integrated Wavvy API with their WooCommerce. Every order triggers automatic WhatsApp confirmation. 100% automated. Zero manual work.

Step 1: Get API Key

Log into Wavvy → API Management → Generate API Key. Copy it somewhere safe. This is your password for API access.

Step 2: Get Session ID

Go to Sessions page. Each WhatsApp number has a Session ID. Copy the ID of number you want to use for sending messages.

Step 3: Send Your First Message

Here's how to send a message using different languages:

Node.js Example

const axios = require('axios');

const sendMessage = async () => {
  try {
    const response = await axios.post('https://wavvy.site/api/send-message', {
      sessionId: 'your-session-id',
      to: '923001234567',  // Pakistan format
      message: 'Hello! Your order #1234 is confirmed.'
    }, {
      headers: {
        'X-API-Key': 'your-api-key',
        'Content-Type': 'application/json'
      }
    });
    
    console.log('Message sent:', response.data);
  } catch (error) {
    console.error('Error:', error.response.data);
  }
};

sendMessage();

Python Example

import requests

def send_message():
    url = 'https://wavvy.site/api/send-message'
    headers = {
        'X-API-Key': 'your-api-key',
        'Content-Type': 'application/json'
    }
    data = {
        'sessionId': 'your-session-id',
        'to': '923001234567',
        'message': 'Hello! Your order #1234 is confirmed.'
    }
    
    response = requests.post(url, json=data, headers=headers)
    print(response.json())

send_message()

PHP Example

<?php
$url = 'https://wavvy.site/api/send-message';
$data = array(
    'sessionId' => 'your-session-id',
    'to' => '923001234567',
    'message' => 'Hello! Your order #1234 is confirmed.'
);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n" .
                     "X-API-Key: your-api-key\r\n",
        'method'  => 'POST',
        'content' => json_encode($data)
    )
);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>

Send Message with Image

// Node.js
await axios.post('https://wavvy.site/api/send-message', {
  sessionId: 'your-session-id',
  to: '923001234567',
  message: 'Check out our new product!',
  mediaUrl: 'https://yoursite.com/product.jpg'
}, {
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  }
});

Send Bulk Messages

// Node.js
const contacts = [
  { number: '923001234567', name: 'Ahmed' },
  { number: '923007654321', name: 'Ali' }
];

for (const contact of contacts) {
  await axios.post('https://wavvy.site/api/send-message', {
    sessionId: 'your-session-id',
    to: contact.number,
    message: `Hi ${contact.name}! Your order is ready.`
  }, {
    headers: { 'X-API-Key': 'your-api-key' }
  });
  
  // Wait 3 seconds between messages (safe speed)
  await new Promise(resolve => setTimeout(resolve, 3000));
}

WooCommerce Integration

Add this to your WordPress theme's functions.php:

add_action('woocommerce_order_status_processing', 'send_whatsapp_confirmation');

function send_whatsapp_confirmation($order_id) {
    $order = wc_get_order($order_id);
    $phone = $order->get_billing_phone();
    $name = $order->get_billing_first_name();
    
    // Remove leading zero, add 92
    $phone = '92' . ltrim($phone, '0');
    
    $message = "Hi $name! Your order #$order_id is confirmed. " .
               "Total: Rs. " . $order->get_total() . ". " .
               "We'll ship within 24 hours!";
    
    $data = array(
        'sessionId' => 'your-session-id',
        'to' => $phone,
        'message' => $message
    );
    
    wp_remote_post('https://wavvy.site/api/send-message', array(
        'headers' => array(
            'X-API-Key' => 'your-api-key',
            'Content-Type' => 'application/json'
        ),
        'body' => json_encode($data)
    ));
}

Shopify Integration

Use Shopify webhooks to trigger WhatsApp messages:

// Your webhook endpoint (Node.js/Express)
app.post('/shopify-webhook', async (req, res) => {
  const order = req.body;
  
  await axios.post('https://wavvy.site/api/send-message', {
    sessionId: 'your-session-id',
    to: '92' + order.customer.phone.replace(/^0+/, ''),
    message: `Hi ${order.customer.first_name}! ` +
             `Order #${order.order_number} confirmed. ` +
             `Total: Rs. ${order.total_price}`
  }, {
    headers: { 'X-API-Key': 'your-api-key' }
  });
  
  res.sendStatus(200);
});

Error Handling

try {
  const response = await axios.post(url, data, { headers });
  
  if (response.data.success) {
    console.log('Message sent successfully');
  } else {
    console.error('Failed:', response.data.error);
  }
} catch (error) {
  if (error.response) {
    // API returned error
    console.error('API Error:', error.response.data);
  } else {
    // Network error
    console.error('Network Error:', error.message);
  }
}

Rate Limits

API rate limits depend on your plan:

Important

Keep your API key secret! Don't commit it to GitHub. Don't share it publicly. If leaked, regenerate immediately from Wavvy dashboard.

Phone Number Format

Always use international format without + sign:

Testing

Test API with curl command:

curl -X POST https://wavvy.site/api/send-message \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "your-session-id",
    "to": "923001234567",
    "message": "Test message"
  }'

Complete Documentation

Full API docs with all endpoints: wavvy.site/docs/api

API integration takes 10-15 minutes. Once set up, everything runs automatically. Your website talks to WhatsApp, customers get instant updates, you focus on growing business. Start with simple order confirmations, expand from there.

Ready to Automate Your WhatsApp?

Start free forever. No credit card required.