Send SMS 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&recipients=PHONE_NUMBER&message=MESSAGE_TO_SEND
Parameters:
- apikey: Your unique API key.
- recipients: The recipient's phone number.
- message: The message to send.
Example:
GET https://api.smsmobileapi.com/sendsms?apikey=YOUR_API_KEY&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 \
-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.
Get SMS API
This API endpoint is used to retrieve SMS messages received on the smartphone.
https://api.smsmobileapi.com/getsms/?apikey=YOUR_API_KEY
Parameter:
- recipients: The mobile number of the recipient.
- message: The message to send.
- apikey: The API key you have or will receive.
Delete SMS API
This API endpoint is used to delete SMS messages from the server log of SMS Mobile API
https://api.smsmobileapi.com/deletesms/?apikey=YOUR_API_KEY
Parameter:
- apikey: The API key you have.
- guid_message: The unique ID of the message to delete.
- date_start: If used alone, deletes all messages from the specified day.
- date_start and date_end: Combined to delete messages within a specified period.
Note: The deleted SMS are only those stored in the logs of your mobile app account. SMS on the mobile device itself will not be deleted, as we do not have access to them.
发送短信
WSDL URL
https://api.smsmobileapi.com/sendsms/wsdl/sendsms.wsdl
Parameters:
- recipients: The mobile number of the recipient.
- message: The message to send.
- apikey: The API key you have or will receive.
Exemple
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("recipients" =>$_GET['recipients'],"message" =>$_GET['message'],"apikey" =>$_GET['apikey']));
print_r($result);
发送短信
Basic cURL Command
You can use the following cURL command to send an SMS via the SMSmobileAPI:
curl -X POST https://api.smsmobileapi.com/sendsms/ \
-d "recipients=PHONE_NUMBER" \
-d "message=YOUR_MESSAGE" \
-d "apikey=YOUR_API_KEY"
cURL Example in PHP
If you're using PHP, here's how you can send an SMS using cURL:
<?php
$url = 'https://api.smsmobileapi.com/sendsms/';
$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;
?>
This PHP example demonstrates how to send a POST request using cURL to the SMSmobileAPI, passing the necessary parameters as an associative array.
发送短信
Use our officiel Python Module : https://smsmobileapi.com/python/ or use the manuel way ...
Using the `requests` Library
The `requests` library is a popular and simple HTTP library for Python. Here's how you can use it to send an SMS via the SMSmobileAPI:
import requests
url = "https://api.smsmobileapi.com/sendsms/"
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 message to a specific phone number.
Using the `http.client` Library
The `http.client` library is included in the standard library of Python and can also be used to interact with your 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/", params, headers)
response = conn.getresponse()
data = response.read()
print(data.decode("utf-8"))
conn.close()
This example shows how to use the `http.client` library to send a POST request to the API. The parameters are URL-encoded and sent with the appropriate headers.
发送短信
Using the `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 an SMS via the SMSmobileAPI:
const url = "https://api.smsmobileapi.com/sendsms/";
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));
This example demonstrates how to send a POST request using the `fetch` API, which is supported in most modern browsers.
Using `XMLHttpRequest`
If you need to support older browsers, you can use the `XMLHttpRequest` object:
const xhr = new XMLHttpRequest();
const url = "https://api.smsmobileapi.com/sendsms/";
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);
This example shows how to use `XMLHttpRequest` to send a POST request, providing compatibility with older browsers that may not support `fetch`.
发送短信
Using the `axios` Library
The `axios` library is a popular HTTP client for Node.js. Here's how you can use it to send an SMS via the SMSmobileAPI:
const axios = require('axios');
const url = 'https://api.smsmobileapi.com/sendsms/';
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);
});
This example demonstrates how to send a POST request using `axios` in Node.js to interact with the SMSmobileAPI.
发送短信
Using the `Net::HTTP` Library
You can use the `Net::HTTP` library in Ruby to send an SMS via the SMSmobileAPI:
require 'net/http'
require 'uri'
uri = URI.parse("https://api.smsmobileapi.com/sendsms/")
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
This example demonstrates how to send a POST request using `Net::HTTP` in Ruby to the SMSmobileAPI.