Please note that this documentation is for developers only.
Simple Membership plugin has an API Addon that allows you to query a member’s account info using a standard HTTP POST request.
Enabling the API
If you want to use this API then download and install the SWPM API addon and then enable it in the settings.
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
The following is a screenshot of the API settings menu:
Enable the API and take note of the API key so you can use it.
Using the API
To query an user account, it’s required to make POST request to your WP install’s home URL (example: https://yourdomain.com).
Required parameters to access the API are:
- swpm_api_action = query
- key = api key
Minimum Required User Info
Minimum required user info parameter to query a user is the following:
- member_id or email
Code Example
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"}
Query Using HTTP GET
In order to query a member account via HTTP GET request, use the following format:
http://www.example.com/?swpm_api_action=query&key=YOURKEY&member_id=123
Replace www.example.com, YOURKEY and 123 with the actual values.