import requests
import json
url = "https://darajapay.com/api/v1/whatsapp/send"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
data = {
"message_type": "text",
"session": "YOUR_SESSION_ID",
"message": "Hello, this is a test message",
"recipient": "254712345678"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Node.js
const axios = require('axios');
const data = {
message_type: 'text',
session: 'YOUR_SESSION_ID',
message: 'Hello, this is a test message',
recipient: '254712345678'
};
const config = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
}
};
axios.post('https://darajapay.com/api/v1/whatsapp/send', data, config)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
Java
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class WhatsAppExample {
public static void main(String[] args) {
String url = "https://darajapay.com/api/v1/whatsapp/send";
String requestBody = """
{
"message_type": "text",
"session": "YOUR_SESSION_ID",
"message": "Hello, this is a test message",
"recipient": "254712345678"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer YOUR_API_KEY")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
}
C#
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var client = new HttpClient();
var url = "https://darajapay.com/api/v1/whatsapp/send";
var data = new
{
message_type = "text",
session = "YOUR_SESSION_ID",
message = "Hello, this is a test message",
recipient = "254712345678"
};
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
var json = JsonSerializer.Serialize(data);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://darajapay.com/api/v1/whatsapp/send"
data := map[string]string{
"message_type": "text",
"session": "YOUR_SESSION_ID",
"message": "Hello, this is a test message",
"recipient": "254712345678",
}
jsonData, _ := json.Marshal(data)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}