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.

Tagged . Bookmark the . Last updated: .