<?php

//Documentation reference: https://simple-membership-plugin.com/simple-membership-api-creating-member-account-using-http-post-request/

/*
This example code shows how to query a member account using the API. It uses CURL PHP library to send the HTTP POST request.
*/

$post_url = 'https://www.example.com/';//The homepage URL of your site (where the API addon is installed)
$secret_key = '8c44c3a0b5aa49ab45d82af4acb42149';//The secret key (from the API settings page)

$post_arr = array(
	'swpm_api_action' => 'query',
	'key' => $secret_key,
	'email' => 'john.doe@gmail.com',
);

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, $post_url );
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) {
    echo "<br />API response dump below.<br />------------------------<br />";
	var_dump( $res );
} else {
	//API returned unexpected result
	echo "<br />Error occurred! API returned unexpected result. Check if CURL PHP library is intalled correctly on this server.<br />";
}
