Send SMS via API

Its posible send sms from web form ?

this is the code i tried

<form name='f1' action='http://172.31.224.56/api/cmd.sms.sendMessage' method="POST">
	Address:<input type="text" name='address'><br>
	Content: <input type="text" name='content'><br>
	ConnId: <input type="text" name='connId'><br>
	<input type='submit' value='Send'>
</form>

response
{
“stat”: “fail”,
“code”: 401,
“message”: “Unauthorized”
}

some help ?

look at the api calls , you have to authenticate and store a token first before this call I believe.

thanks. i will search the token.

i change my code to use curl but still dont working

$client = curl_init();
	curl_setopt($client, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($client, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($client, CURLOPT_FOLLOWLOCATION, true);
	//curl_setopt($client, CURLOPT_HEADER, true);	
	curl_setopt($client, CURLOPT_URL, "http://172.31.224.56/api/login");		
	curl_setopt($client, CURLOPT_POST, 1);
	curl_setopt($client, CURLOPT_POSTFIELDS, "username=admin&password=XXXX");
	curl_setopt($client, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_exec($client);
	

	curl_setopt($client, CURLOPT_URL, "http://172.31.224.56/api/cmd.sms.sendMessage");	
	curl_setopt($client, CURLOPT_POSTFIELDS, "address=+569978223&content=Test");
	
	curl_exec($client);
	curl_close($client)

response
{ “stat”: “ok”, “response”: { “permission”: { “GET”: 1, “POST”: 1 } } }
{ “stat”: “fail”, “code”: 400, “message”: “Wrong address format” }

Test something basic after login like getting cpu status does that work?

2 Likes

Phone number (address) format? Eg plus symbol, country code, full telephone number. Ex +19711234567 for an US based number.

Here you can find a sample test case using POSTMAN, described by sitloongs. Please try this first, and check if the address is correct.

Like @Jonathan_Pitts mentioned, try an api-function that does not need any parameter like api/info.firmware.

1 Like

thanks. solved.

2 Likes

Hi,
The 401 Unauthorized response usually means the request is reaching the device/API, but it’s missing proper authentication or required parameters.

In your case, the issue is likely not the HTML form itself but how the API expects authentication. Most Peplink/Pepwave APIs require either:

  • Session authentication (login first and use cookie/session)
  • Or API key/token (if supported in your firmware)

A few things to check:

  1. Authentication requirement
    The /api/cmd.sms.sendMessage endpoint typically needs an authenticated session.
    Try logging in via the API first and then sending the request using the same session (Postman helps here).
  2. Test with Postman instead of form
    Forms don’t handle cookies/session easily.
    Use Postman to:
  • Login endpoint
  • Capture session/cookie
  • Then call sendMessage
  1. Check firmware/API mode
    Some endpoints behave differently depending on firmware version or whether API access is enabled.
  2. Use a simpler endpoint first
    Try something like /api/info (no auth or basic auth depending on setup) to confirm connectivity before sending SMS.
    Important note:
    Sending SMS via web form directly usually fails in these setups because authentication/session handling is required. That’s why API tools or backend scripts work better than plain HTML forms.
    If you can share your firmware version or how you’re authenticating, I can help you structure the exact request