Send WhatsApp API
The SMSMobile API supports two authentication methods: using a simple API Key or the OAuth2 protocol with a client ID and client secret.
1. API Key Authentication for Send SMS
This method requires an API Key that can be included as a parameter in either a GET or POST request. It is a straightforward way to authenticate your API requests.
https://api.smsmobileapi.com/sendsms?apikey=YOUR_API_KEY&waonly=yes&recipients=PHONE_NUMBER&message=MESSAGE_TO_SEND
Parametreler:
- apikey: Your unique API key.
- recipients: The recipient's phone number (The number must be available on WhatsApp).
- message: The message to send (Multiple lines possible).
- waonly: must have the value yes -> Required to specify that only one WhatsApp message should be sent
Example:
GET https://api.smsmobileapi.com/sendsms?apikey=YOUR_API_KEYY&waonly=yes&recipients=+1234567890&message=Hello%20World
2. OAuth2 Authentication for Send SMS
OAuth2 provides a more secure and scalable authentication method.
You will need to use a client ID and client secret to obtain an access token, which should then be included in your API requests using the Authorization header.
The client_id and client_secret are available in your dashboard, accessible after installing the app and creating an account on your mobile device.
Download the mobile app now veya
access your dashboard. Obtaining an Access Token
To get an access token, send a POST request to the token endpoint with your client ID and client secret.
curl -X POST https://api.smsmobileapi.com/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=1ab0ex4b4c1ef2c800690d" \
-d "client_secret=3ed108a93d0414074b94364290b6a7348475e93a0567005"
Using the Access Token:
Once you have the access token, include it in the Authorization header of your API requests:
curl -X POST https://api.smsmobileapi.com/sendsms?waonly=yes \
-H "Authorization: Bearer abc123xyz456" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "recipients=+1234567890" \
-d "message=Hello"
Which Method Should You Use?
- Use API Key Authentication for quick and straightforward integrations.
- Use OAuth2 Authentication for enhanced security and scalability in your integrations.
For more details, please refer to the full documentation.
Send WhatsApp message
WSDL URL
https://api.smsmobileapi.com/sendsms/wsdl/sendsms.wsdl
Parametreler:
- recipients: The mobile number of the recipient.
- message: The message to send.
- apikey: The API key you have or will receive.
- waonly: must have the value yes -> Required to specify that only one WhatsApp message should be sent.
Örnek
require_once "lib/nusoap.php";
$client = new nusoap_client("https://api.smsmobileapi.com/sendsms/wsdl/sendsms.wsdl", true);
$error = $client->getError();
$result = $client->call("sendSms", array("waonly" =>"yes","recipients" =>$_GET['recipients'],"message" =>$_GET['message'],"apikey" =>$_GET['apikey']));
print_r($result);
Send WhatsApp
Temel cURL Komutu
You can use the following cURL command to send a WhatsApp message via the SMSmobileAPI:
curl -X POST https://api.smsmobileapi.com/sendsms/?waonly=yes \
-d "recipients=PHONE_NUMBER" \
-d "message=YOUR_MESSAGE" \
-d "apikey=YOUR_API_KEY"
PHP'de cURL Örneği
If you're using PHP, here's how you can send an WhatsApp message using cURL:
<?php
$url = 'https://api.smsmobileapi.com/sendsms/?waonly=yes';
$data = array(
'recipients' => 'PHONE_NUMBER',
'message' => 'YOUR_MESSAGE',
'apikey' => 'YOUR_API_KEY'
);
$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_RETURNTRANSFER => true,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
Bu PHP örneği, gerekli parametreleri ilişkisel bir dizi olarak geçirerek cURL kullanarak SMSmobileAPI'ye bir POST isteğinin nasıl gönderileceğini göstermektedir.
Send WhatsApp
Resmi Python Modülümüzü kullanın: https://smsmobileapi.com/python/ veya manuel yolu kullanın ...
`requests` Kütüphanesini Kullanma
The `requests` library is a popular and simple HTTP library for Python. Here's how you can use it to send an WhatsApp message via the SMSmobileAPI:
import requests
url = "https://api.smsmobileapi.com/sendsms/waonly=yes"
payload = {
"recipients": "PHONE_NUMBER",
"message": "YOUR_MESSAGE",
"apikey": "YOUR_API_KEY"
}
response = requests.post(url, data=payload)
print(response.text)
This example demonstrates a simple POST request to the SMSmobileAPI, sending a WhatsApp message to a specific phone number.
`http.client` Kütüphanesini Kullanma
`http.client` kütüphanesi Python'un standart kütüphanesinde yer alır ve API'nizle etkileşim kurmak için de kullanılabilir:
import http.client
import urllib.parse
conn = http.client.HTTPSConnection("api.smsmobileapi.com")
params = urllib.parse.urlencode({
"recipients": "PHONE_NUMBER",
"message": "YOUR_MESSAGE",
"apikey": "YOUR_API_KEY"
})
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn.request("POST", "/sendsms/?waonly=yes", params, headers)
response = conn.getresponse()
data = response.read()
print(data.decode("utf-8"))
conn.close()
Bu örnek, API'ye bir POST isteği göndermek için `http.client` kütüphanesinin nasıl kullanılacağını gösterir. Parametreler URL kodludur ve uygun başlıklarla gönderilir.
Send WhatsApp
`fetch` API'sini kullanma
The `fetch` API is a modern and versatile way to make HTTP requests in JavaScript. Here's how you can use it to send a WhatsApp message via the SMSmobileAPI:
const url = "https://api.smsmobileapi.com/sendsms/?waonly=yes";
const data = {
recipients: "PHONE_NUMBER",
message: "YOUR_MESSAGE",
apikey: "YOUR_API_KEY"
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: new URLSearchParams(data)
})
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.error("Error:", error));
Bu örnek, çoğu modern tarayıcıda desteklenen `fetch` API'sini kullanarak bir POST isteğinin nasıl gönderileceğini göstermektedir.
`XMLHttpRequest` Kullanımı
Daha eski tarayıcıları desteklemeniz gerekiyorsa `XMLHttpRequest` nesnesini kullanabilirsiniz:
const xhr = new XMLHttpRequest();
const url = "https://api.smsmobileapi.com/sendsms/?waonly=yes";
const data = "recipients=PHONE_NUMBER&message=YOUR_MESSAGE&apikey=YOUR_API_KEY";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send(data);
Bu örnek, `fetch` komutunu desteklemeyen eski tarayıcılarla uyumluluk sağlayarak, bir POST isteği göndermek için `XMLHttpRequest` komutunun nasıl kullanılacağını göstermektedir.
Send WhatsApp
`axios` Kütüphanesini Kullanma
The `axios` library is a popular HTTP client for Node.js. Here's how you can use it to send a WhatsApp message via the SMSmobileAPI:
const axios = require('axios');
const url = 'https://api.smsmobileapi.com/sendsms/?waonly=yes';
const data = {
recipients: 'PHONE_NUMBER',
message: 'YOUR_MESSAGE',
apikey: 'YOUR_API_KEY'
};
axios.post(url, data)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
Bu örnek, Node.js'de `axios` kullanılarak SMSmobileAPI ile etkileşime geçmek için bir POST isteğinin nasıl gönderileceğini göstermektedir.
Send WhatsApp
`Net::HTTP` Kütüphanesini Kullanma
You can use the `Net::HTTP` library in Ruby to send a WhatsApp message via the SMSmobileAPI:
require 'net/http'
require 'uri'
uri = URI.parse("https://api.smsmobileapi.com/sendsms/?waonly=yes")
request = Net::HTTP::Post.new(uri)
request.set_form_data(
"recipients" => "PHONE_NUMBER",
"message" => "YOUR_MESSAGE",
"apikey" => "YOUR_API_KEY"
)
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
puts response.body
Bu örnek, Ruby'de `Net::HTTP` kullanılarak SMSmobileAPI'ye bir POST isteğinin nasıl gönderileceğini göstermektedir.