Paid Memberships Pro currently offers support for two APIs available in WordPress: the REST API and the XML-RPC method. This article will provide a high level overview of endpoints available in each method as well as a recipe to demonstrate how developers can build their own basic API for membership data.

Interacting with Paid Memberships Pro through API's


Using the WordPress REST API with Paid Memberships Pro

PMPro offers three WordPress REST API methods. The REST API uses JSON objects to send and receive data in your WordPress site. Check out the REST API Handbook for more information about using this API to interact with your WordPress site.

The three methods available in PMPro include pmpro_rest_api_get_permissions_check, pmpro_rest_api_get_user_level, and pmpro_rest_api_get_has_membership_access.

Read the REST API Documentation

XML-RPC Methods Available in Paid Memberships Pro

There are two XML-RPC methods available in PMPro that extend upon WordPress’ support for this API. You can read more about XML-RPC support in the WordPress Codex here.

The two methods available in PMPro include pmpro.getMembershipLevelForUser and pmpro.hasMembershipAccess. To use either method, you must authenticate the request with a username and password for an Administrator-role user that has the pmpro_xmlrpc capability in the WordPress site.

Read the XML-RPC Documentation

How to Build a Simple RESTful API to get PMPro Data

As an alternative to using these built-in API methods, you can build your own RESTful scripts to return specific data when specific parameters are passed into a WordPress URL.

This method is less secure since there is no user authentication, but it also doesn’t require you to save a username and password in plaintext in a different system that might be used to access parts of your WordPress system you didn’t intend to make public. In general, more measures should be made to make these APIs secure when using them on live sites.

This example that sets up a URL (/?verify=email@domain.com&secret=SOMESECRETHERE) your app can hit and receive a JSON encoded array of membership level data returned for the specified user. This is very similar to the pmpro.getMembershipLevelForUser XML-RPC example above.

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

This entry was posted by Jason Coleman in Recipes and tagged . Bookmark the permalink. Last updated: February 20, 2020. Titled Interacting with Paid Memberships Pro Through APIs

Comments (9)

You need to update the code below (RESTful API to get PMPro Data by email)

$membership_level = pmpro_getMembershipLevelForUser();

to

$membership_level = pmpro_getMembershipLevelForUser($user->ID);

Otherwise you will get always the same result.

I was working a bit with this code and thought I might post my result in case anyone else needed something similar.

In this snippet I send the userid insted of the email to the api.

$user = get_user_by(“login”, str_replace(” “, “+”, ($_REQUEST[‘verify’])));
if(empty($user))
wp_die(“User not found.”);
$user_id = $user->ID;
$membership_level = pmpro_getMembershipLevelForUser($user_id);

I used this in angularjs to call the subscriptionID for users.

I’d like to create a user from a mobile app client (say someone registers using the mobile app, I’d like to create that user in paid membership pro), which API would I be using? The ones stated here only fetch information about the already existing users.

I think Bruce was looking for a way to create a new membership. I’m also interested in this topic. Say we want to take the payment on another platform and create a new membership programmatically? How would one do that>

One of the benefits of an external service I offer is membership to PMP WordPress. I want my external service to call the api and cancel a membership when my external service is not renewed. Can you steer me in the right direction?

How are you giving them membership when they sign up for the external service?

We don’t have an endpoint in the WP REST API to cancel/change membership yet, but we could build one out for you. Or if you go the “custom API” route, you could setup your WP site to listen for something like /wp-admin/admin-ajax.php?action=cancel_member&user_id={user_id}&secretkey={something you keep secret}. Use wp_ajax_nopriv_cancel_member hook, check for the user id, check the secret key, then call pmpro_changeMembershipLevel(0, $user_id)

We can help in the member forums if you need further assistance.

Hi i want to send user data to external system when user register successfully. Can you please tell me on which page data is submit when user fill checkout form and press pay now button?

Leave a Reply

For faster support related to issues on your specific site please open a ticket in our members support area.

Your email address will not be published. Required fields are marked *