const axios = require('axios');
const sendOtp = async () => {
try {
const response = await axios.post('https://your-domain.com/api/messages/send_otp', {
to: '+966500000000',
channel: 'whatsapp',
type: 'otp',
body: 'رمز التحقق الخاص بك هو: 1234'
}, {
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
}
});
console.log(response.data);
} catch (error) {
console.error(error.response ? error.response.data : error.message);
}
};
sendOtp();
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> sendOtp() async {
final url = Uri.parse('https://your-domain.com/api/messages/send_otp');
final response = await http.post(
url,
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json',
},
body: jsonEncode({
'to': '+966500000000',
'channel': 'whatsapp',
'type': 'otp',
'body': 'رمز التحقق الخاص بك هو: 1234',
}),
);
if (response.statusCode == 200) {
print('Success: ${response.body}');
} else {
print('Error: ${response.statusCode} - ${response.body}');
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://your-domain.com/api/messages/send_otp"
payload := map[string]string{
"to": "+966500000000",
"channel": "whatsapp",
"type": "otp",
"body": "رمز التحقق الخاص بك هو: 1234",
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import Foundation
func sendOtp() {
guard let url = URL(string: "https://your-domain.com/api/messages/send_otp") else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer YOUR_API_TOKEN", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let body: [String: Any] = [
"to": "+966500000000",
"channel": "whatsapp",
"type": "otp",
"body": "رمز التحقق الخاص بك هو: 1234"
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data, let responseString = String(data: data, encoding: .utf8) {
print("Response: (responseString)")
}
}
task.resume()
}
{
"to": "+966500000000",
"channel": "whatsapp",
"type": "otp",
"body": "رمز التحقق الخاص بك هو: 1234"
}
curl -X POST https://your-domain.com/api/messages/send_otp \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"to": "+966500000000",
"channel": "whatsapp",
"type": "otp",
"body": "رمز التحقق الخاص بك هو: 1234"
}'
<?php
$ch = curl_init("https://your-domain.com/api/messages/send_otp");
$data = [
"to" => "+966500000000",
"channel" => "whatsapp",
"type" => "otp",
"body" => "رمز التحقق الخاص بك هو: 1234"
];
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_TOKEN",
"Content-Type: application/json"
],
CURLOPT_POSTFIELDS => json_encode($data)
]);
$response = curl_exec($ch);
curl_close($ch);