Please note that this documentation is for expert developers only. You will need to hire our developer if you need any help with this.
Simple Membership plugin has an API Addon that allows you to update a member’s account using a standard HTTP POST request.
Table of Contents
Ensure the API Addon is Enabled
If you haven’t done so already, visit the SWPM API addon page to download it and then enable it in the settings.
Enabling the API
When the Simple Membership API addon is active, you can access the settings of this addon from the following interface:
Simple Membership -> Settings -> Addons Settings -> API Addon Settings
Enable the API and take note of the API key so you can use it.
Using the API to Update a Profile
To update an user account, it’s required to make POST request to your WP install’s home URL (example: https://example.com)
Note: To create a user, you must use an HTTP POST request; a GET request is not applicable.
Required parameters to access the API are:
- swpm_api_action = update
- key = api key
Parameter names are equal to members_tbl column names and format. Example: if you want to set company name for the user, you just pass company_name parameter:
company_name = Imaginary Company Ltd.
To set a password for user, you just need to provide it in plain text (using the input parameter “password”). The addon will handle the rest by itself.
Minimum Required User Info
Minimum required user info parameter to update a user is the following:
- member_id
Note: You can’t update the ‘user_name’ field.
Code Example
PHP Code Example
The following code example shows how to update a user profile using cURL:
$post_arr = array(
'swpm_api_action' => 'update',
'key' => '8c44c3a0b5aa49ab45d82af4acb42149',
'member_id' => '36',
'first_name' => 'John',
'last_name' => 'Smith',
'email' => 'johns@example.com',
'password' => 'testpass0998',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'curl');
curl_setopt($ch, CURLOPT_POSTFIELDS,
$post_arr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
curl_close ($ch);
$res=json_decode($response,true);
if ($res!==NULL) {
var_dump($res);
} else {
//API returned unexpected result
echo "Error occurred";
}
API Response
You get JSON string similar to the following:
{"result":"success"},"message":"Member updated successfully","member":{"first_name":"John","last_name":"Smith","email":"'johns@example.com","company_name":null,"account_state":"active","membership_level":2,"reg_code":"62c5220bf960bf379b908b4190390a88","member_id":36}}
The updated user’s info is shown.
If there is an error, the response will be similar to the following:
{{"result":"failure"},"errors":{"email":"Email is already used. (johns@example.com )"},"message":"Errors occurred"}
JavaScript Code Example
The following code example shows how to update a user profile using JavaScript code.
// Update a member account using the Simple Membership API
// Replace the URL, API key, and member details with your own values.
const apiUrl = 'https://www.example.com/'; // Your WordPress site's home URL
const formData = new FormData();
formData.append('swpm_api_action', 'update');
formData.append('key', '8c44c3a0b5aa49ab45d82af4acb42149');
formData.append('member_id', '36');
formData.append('first_name', 'John');
formData.append('last_name', 'Smith');
formData.append('email', 'johns@example.com');
formData.append('membership_level', '2');
//formData.append('password', 'newpassword123');
fetch(apiUrl, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.result === 'success') {
console.log('Member updated successfully:', data.member);
} else {
console.error('Update failed:', data.message, data.errors || '');
}
})
.catch(error => {
console.error('Request error:', error);
});
Notes
- Use FormData (not JSON.stringify) so PHP populates $_POST correctly.
- The Content-Type header is set automatically by the browser when using FormData, do not set it manually.
- All parameters are the same as in the PHP/cURL example; only the transport mechanism differs.
- password is passed in plain text; the addon handles hashing server-side.