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
Parámetros:
- 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 o
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
URL WSDL
https://api.smsmobileapi.com/sendsms/wsdl/sendsms.wsdl
Parámetros:
- 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.
Ejemplo
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
Comando básico de 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"
Ejemplo de cURL en PHP
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;
?>
Este ejemplo de PHP demuestra cómo enviar una solicitud POST usando cURL a SMSmobileAPI, pasando los parámetros necesarios como una matriz asociativa.
Send WhatsApp
Utilice nuestro módulo oficial de Python: https://smsmobileapi.com/python/ o usa el método manual...
Uso de la biblioteca `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.
Uso de la biblioteca `http.client`
La biblioteca `http.client` está incluida en la biblioteca estándar de Python y también se puede utilizar para interactuar con su 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()
Este ejemplo muestra cómo utilizar la biblioteca `http.client` para enviar una solicitud POST a la API. Los parámetros están codificados en URL y se envían con los encabezados correspondientes.
Send WhatsApp
Usando la API `fetch`
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));
Este ejemplo demuestra cómo enviar una solicitud POST utilizando la API `fetch`, que es compatible con la mayoría de los navegadores modernos.
Usando `XMLHttpRequest`
Si necesita compatibilidad con navegadores más antiguos, puede utilizar el objeto `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);
Este ejemplo muestra cómo utilizar `XMLHttpRequest` para enviar una solicitud POST, proporcionando compatibilidad con navegadores más antiguos que pueden no soportar `fetch`.
Send WhatsApp
Usando la biblioteca `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);
});
Este ejemplo demuestra cómo enviar una solicitud POST usando `axios` en Node.js para interactuar con SMSmobileAPI.
Send WhatsApp
Uso de la biblioteca `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
Este ejemplo demuestra cómo enviar una solicitud POST utilizando `Net::HTTP` en Ruby a SMSmobileAPI.