Newsletter Unsubscribe Endpoint
REST API endpoint to unsubscribe users from your SMS newsletter.
This endpoint allows you to unsubscribe users from your SMS newsletter programmatically.
Endpoint
POST /wp-json/wpsms/v1/newsletter/unsubscribe
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
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Subscriber’s name |
mobile | string | Yes | Subscriber’s mobile number |
group_id | string | No | Specific group ID to unsubscribe from |
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',
'group_id' => '5', // Optional
);
// The endpoint URL
$url = 'https://site.com/wp-json/wpsms/v1/newsletter/unsubscribe';
// 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/unsubscribe' \
--header 'Authorization: Basic YOUR_BASE64_CREDENTIALS' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=User Name' \
--data-urlencode 'mobile=912345678' \
--data-urlencode 'group_id=5'
Response
Success
{
"message": "Your mobile number has been successfully unsubscribed.",
"error": [],
"data": []
}
Related
- Newsletter Subscribe Endpoint - Subscribe users to newsletter
- Newsletter Verify Endpoint - Verify subscriber phone numbers
Last updated: December 23, 2024