Overview of Using the MemberPress Developer Tools Addon

This add-on is only included with your purchase of the MemberPress Plus and Pro Editions.

If you're not a developer, you might find our Zapier integration or the Uncanny Automator easier to use.

Our MemberPress Developer Tools Add-on extends MemberPress to include a full REST API and full Webhook event capability.

If the documentation on this page seems light for developer tools that's because all of the documentation for the webhook events and REST API urls can be found in the plugin's interface. It will actually give you dynamic results to work from and an ability to test webhooks directly from your site.

Getting Started couldn't be easier ... here's how:

  1. Ensure your MemberPress activation key is for a MemberPress Developer Edition License.
  2. Install the MemberPress Developer Tools Add-on by going to "MemberPress" -> "Add-ons" page and clicking on the "Install Add-on" button under the add-on.
  3. If you want to use MemberPress' REST API then you'll need to run WordPress 4.7+ or you'll need to install the WP REST API plugin (Version 2).
  4. Once the Developer Tools add-on is installed and activated you should see a new menu item on your MemberPress menu:

  5. From the Developer Menu you'll now be able to setup Webhooks, view dynamic documentation on and test Webhook Events and view dynamic documentation on all of MemberPress's REST API urls:

Sample PHP cURL Code

This example adds a Member, plus assigns them to a Membership (via a transaction), and also triggers a welcome email in the process:

<?php
$url = 'http://testsite.w6.wpsandbox.pro/wp-json/mp/v1/members';

$ch = curl_init($url);

$data_string = json_encode(
  [
    'email'               => '[email protected]',
    'username'            => '[email protected]',
    'first_name'          => 'test',
    'last_name'           => 'test_last_name',
    'send_welcome_email'  => true, // Trigger a welcome email - this only works if adding a transaction (below)
    'transaction'         => [
      'membership'  => 376, // ID of the Membership
      'amount'      => '0.00',
      'total'       => '0.00',
      'tax_amount'  => '0.00',
      'tax_rate'    => '0.000',
      'trans_num'   => 'mp-txn-' . uniqid(),
      'status'      => 'complete',
      'gateway'     => 'free',
      'created_at'  => gmdate( 'c' ),
      'expires_at'  => '0000-00-00 00:00:00'
    ]
  ]
);

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string );

$header = array();
$header[] = 'MEMBERPRESS-API-KEY: MgCUGSO5Qg'; // Your API KEY from MemberPress Developer Tools Here
$header[] = 'Content-Type: application/json';
$header[] = 'Content-Length: ' . strlen($data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

$response = curl_exec($ch);

if(curl_errno($ch)){
  throw new Exception(curl_error($ch));
}

echo $response;

curl_close($ch);

Troubleshooting Basic Authentication

The preferred method for authentication is via the API Key provided by MemberPress Developer Tools. However, we know that many of you also use the less secure - Basic Authentication method - to connect to the WP-API. This can present a few challenges though, which hopefully the information below can assist you with.

If you're struggling to get Basic Authentication to work, be sure you've installed this plugin and followed its instructions.

A typical Basic Auth request should look like the following:
Header Name: Authorization
Header Value: Basic base64_encode( wp_admin_user_login_here:application_passwords_password_here )

Your user should have the remove_users capability or MemberPress Developer Tools will return a 401 response.

If you're still unable to authenticate, then your hosting server may have some configuration issues. Read more about the most common cause here. Application Passwords plugin needs the PHP_AUTH_USER and PHP_AUTH_PW variables to be set. If they're not set, Application Passwords will fail to authenticate the user and you'll need to work with your webhost to correct it. Typically it requires adding something like the following to .htaccess file:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

If all else fails, again it is best to just use the API Key in the MEMBERPRESS-API-KEY HTTP request header instead. Below is some sample code with the API Key and PHP cURL:

<?php
$url = 'http://testsite.com/wp-json/mp/v1/me';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$headers = [ 'MEMBERPRESS-API-KEY: MdCUPSO5Qr', 'Content-Type: application/json' ];
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
$response = curl_exec( $ch );
if( curl_errno( $ch ) ) { throw new Exception( curl_error( $ch ) ); }
curl_close($ch);
echo $response;

Troubleshooting Webhooks

If your test webhooks are working, but your live tests are not firing. Then most likely WP Cron is disabled, or is not working as it should. MemberPress Developer Tools rely on WP Cron to send out the webhooks.

The easiest way to verify this is the case, is to check the wp_mepr_jobs table in your database and see if the Webhook jobs are stuck there with a status of "pending".

When possible, we'd recommend disabling page load based WP Cron, and instead triggering it from a server-side cron that runs every minute. HostGator has a great article on doing this here. - and WordPress.org has some additional information here. Unfortunately we cannot assist you with this, your webhost will need to help you set this up.

If you're unable to get WP Cron firing correctly, even after enabling a server-side cron, then you may (as a last resort) need to issue the following query:

UPDATE wp_options SET option_value = '' WHERE option_name = 'cron';