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 query a member’s account info using a standard HTTP POST request.
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 Query a Profile
To query an existing member profile, send an HTTP request (POST or GET) to the home URL of your WordPress installation (example: https://simple-membership-plugin.com).
Required parameters for the query API endpoint:
- swpm_api_action=query
- key=<the-api-key>
- email=<the-email-address-of-the-profile>
The ‘query’ endpoint can also be accessed using the ‘member_id’ parameter instead of the ’email’ parameter.
Query Profile Example Using HTTP GET Request
In order to query a member account via HTTP GET request, use the following format:
https://www.example.com/?key=422b82d368b982fc5a65ab&swpm_api_action=query&email=john.doe@gmail.com
OR the following (if you want to query by ‘member_id’ of the member):
https://www.example.com/?key=422b82d368b982fc5a65ab&swpm_api_action=query&member_id=1
Query Profile Example Using HTTP POST Request
The following code example shows how to query a user with minimum parameters. It uses HTTP POST using cURL:
$post_arr = array(
'swpm_api_action' => 'query',
'key' => '8c44c3a0b5aa49ab45d82af4acb42149',
'member_id' => '36',
);
$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 found","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 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"}