Newsletter Subscribe Endpoint

REST API endpoint to subscribe users to your SMS newsletter.

This endpoint allows you to subscribe users to your SMS newsletter programmatically. Useful for integrating with custom forms or form builders that aren’t directly supported.

Endpoint

POST /wp-json/wpsms/v1/newsletter

Authentication

As of version 6.9.4, authentication is required for all /newsletter/* endpoints. The authenticated user must have the wpsms_subscribers capability.

Use WordPress Application Passwords for authentication. Learn more about WordPress REST API authentication.

Request Parameters

ParameterTypeRequiredDescription
namestringYesSubscriber’s name
mobilestringYesSubscriber’s mobile number

Examples

PHP with wp_remote_post

<?php
// WordPress username and Application Password
$username = 'your-username';
$password = 'your-application-password';

// Encode credentials for Basic Authentication
$auth = base64_encode("$username:$password");

// Subscriber's information
$postData = array(
    'name'   => 'User Name',
    'mobile' => '912345678'
);

// The endpoint URL
$url = 'https://site.com/wp-json/wpsms/v1/newsletter';

// Set up the arguments
$args = array(
    'headers' => array(
        'Authorization' => 'Basic ' . $auth,
        'Content-Type'  => 'application/x-www-form-urlencoded',
    ),
    'body' => $postData,
);

// Make the request
$response = wp_remote_post($url, $args);

if (is_wp_error($response)) {
    echo "Error: " . $response->get_error_message();
} else {
    $body = wp_remote_retrieve_body($response);
    echo "Response: $body";
}

cURL

curl --location --request POST 'https://site.com/wp-json/wpsms/v1/newsletter' \
--header 'Authorization: Basic YOUR_BASE64_CREDENTIALS' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=User Name' \
--data-urlencode 'mobile=912345678'

Response

Success

{
  "message": "Your mobile number has been successfully subscribed.",
  "error": [],
  "data": []
}

Last updated: December 23, 2024