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
パラメータ:
- 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 または
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
パラメータ:
- 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.
例
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
基本的な cURL コマンド
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 での cURL の例
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;
?>
この PHP の例は、必要なパラメータを連想配列として渡しながら、cURL を使用して POST リクエストを SMSmobileAPI に送信する方法を示しています。
Send WhatsApp
公式 Python モジュールを使用します。 https://smsmobileapi.com/python/ または手動で行うこともできます...
`requests` ライブラリの使用
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` ライブラリの使用
`http.client` ライブラリは Python の標準ライブラリに含まれており、API とのやり取りにも使用できます。
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()
この例では、`http.client` ライブラリを使用して API に POST リクエストを送信する方法を示します。パラメータは URL エンコードされ、適切なヘッダーとともに送信されます。
Send WhatsApp
`fetch` API の使用
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));
この例では、ほとんどの最新ブラウザでサポートされている `fetch` API を使用して POST リクエストを送信する方法を示します。
`XMLHttpRequest` の使用
古いブラウザをサポートする必要がある場合は、`XMLHttpRequest` オブジェクトを使用できます。
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);
この例では、`XMLHttpRequest` を使用して POST リクエストを送信し、`fetch` をサポートしていない可能性のある古いブラウザとの互換性を確保する方法を示します。
Send WhatsApp
`axios` ライブラリの使用
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);
});
この例では、Node.js で `axios` を使用して POST リクエストを送信し、SMSmobileAPI と対話する方法を示します。
Send WhatsApp
`Net::HTTP` ライブラリの使用
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
この例では、Ruby で `Net::HTTP` を使用して POST リクエストを SMSmobileAPI に送信する方法を示します。