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 ou
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 do 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.
Exemplo
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 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"
Exemplo cURL em 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 exemplo PHP demonstra como enviar uma solicitação POST usando cURL para o SMSmobileAPI, passando os parâmetros necessários como uma matriz associativa.
Send WhatsApp
Use nosso módulo Python oficial: https://smsmobileapi.com/python/ ou use o método manual...
Usando a 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.
Usando a biblioteca `http.client`
A biblioteca `http.client` está incluída na biblioteca padrão do Python e também pode ser usada para interagir com sua 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 exemplo mostra como usar a biblioteca `http.client` para enviar uma solicitação POST para a API. Os parâmetros são codificados em URL e enviados com os cabeçalhos apropriados.
Send WhatsApp
Usando a 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 exemplo demonstra como enviar uma solicitação POST usando a API `fetch`, que é suportada na maioria dos navegadores modernos.
Usando `XMLHttpRequest`
Se precisar de suporte a navegadores mais antigos, você pode usar o 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 exemplo mostra como usar `XMLHttpRequest` para enviar uma solicitação POST, fornecendo compatibilidade com navegadores mais antigos que podem não suportar `fetch`.
Send WhatsApp
Usando a 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 exemplo demonstra como enviar uma solicitação POST usando `axios` no Node.js para interagir com o SMSmobileAPI.
Send WhatsApp
Usando a 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 exemplo demonstra como enviar uma solicitação POST usando `Net::HTTP` em Ruby para o SMSmobileAPI.