Memberstack RESTful API

Article author
Josh Lopez
  • Updated

Using Memberstack 2.0? There is an updated version of this article here.

Memberstack has a RESTful API that makes it possible for developers to interact with their website’s member data!

 

Side note: We're working on a new version of Memberstack that's 10x more powerful for developers. Join the Developer Program for early access.

 

At Memberstack, we’re continuously working hard to make the platform more accessible to both designers and developers. We’ve recently launched a new RESTful API that makes it possible for developers to interact with their website’s member data! The new API allows developers to programmatically query, update, and delete their members.

 

In order to authorize the requests, a developer needs to obtain an API key through the Memberstack dashboard. This API key is linked to the website from which you generated it and is used by the API to identify your selected website.

 

Important: Because this is a RESTful API and requires an API key, this API only works in a backend server and not in the Front-End. Using this on the Front-End would expose your API key which will allow anyone to start manipulating your data.

 

Getting members

The API makes it possible to query all members that are associated with the website your API key is linked to! Developers can use any HTTP request library or a simple cURL command to request the member data. The rate limit is 60 requests per second.

const fetch = require('node-fetch')


async function getMembers() {
const res = await fetch("https://api.memberstack.com/v1/members", {
headers: { "X-API-KEY": "..." }
});

const data = await res.json();
console.log(data);
}

 

The member's endpoint returns an object containing:

  • A numeric `count field, which represents the total amount of members that are associated with that website,

  • A boolean has_more field, which indicates whether there are more members to be queried besides the members that have currently been returned. By default, the maximum amount of members that get returned from the endpoint is 100.

  • A members array, which contains the queried member objects.

Developers can choose how they want the members to be queried by adding a page or limit query parameter.

 

The limit query parameter adds the possibility to decide how many members should get returned.

s_4A1162FE1E156638C2A9B54B7B2D4418E91ABB101BF2B7B5D241A6349A6034CC_1593194028273_Screen%2BShot%2B2020-06-26%2Bat%2B10.53.34%2BAM.png

 

The page query parameters make it possible to skip a certain amount of members, which by default start from the very first member. (Please use page instead of skip)

s_4A1162FE1E156638C2A9B54B7B2D4418E91ABB101BF2B7B5D241A6349A6034CC_1593194128650_Screen%2BShot%2B2020-06-26%2Bat%2B10.55.20%2BAM.png

 

Both query parameters can be combined in order to skip a certain amount of members and limit the amount of members that get returned! (Please use page instead of skip)

s_4A1162FE1E156638C2A9B54B7B2D4418E91ABB101BF2B7B5D241A6349A6034CC_1593194173660_Screen%2BShot%2B2020-06-26%2Bat%2B10.56.05%2BAM.png

 

Interacting with a member

The API allows developers to get, update, and delete a specific member. Each member has a unique identifier that is used in order to make these actions possible.

 

Getting a member

In order to get a member, a developer can make a GET request to the API member’s endpoint with the corresponding member’s id. The rate limit is 60 requests per second.

 

Note: It’s not possible to retrieve a member by email – you’ll need to retrieve by ID.

 

s_4A1162FE1E156638C2A9B54B7B2D4418E91ABB101BF2B7B5D241A6349A6034CC_1593194528798_Screen%2BShot%2B2020-06-26%2Bat%2B11.02.00%2BAM.png

 

A member object containing the data of the member with that unique identifier gets returned.

const fetch = require('node-fetch');

async function updateMember() {
const res = await fetch("https://api.memberstack.com/v1/members/3jk90", {
method: "GET",
headers: { "X-API-KEY": "..." }
});

const data = await res.json();
console.log(data);
};

 

Updating a member

Developers can update a member by making a POST request to the API member’s endpoint with the corresponding member’s id and the data which they want to update the member with. A member’s email, password, customFields, and metaData are all able to be updated. The rate limit is 60 requests per second.

const fetch = require('node-fetch')


async function updateMember() {
const res = await fetch("https://api.memberstack.com/v1/members/3jk90", {
method: "POST",
headers: { "X-API-KEY": "..." },
body: JSON.stringify({
metaData: { username: "johndoe1990" }
})
});

const data = await res.json();
console.log(data);
}

The metaData has a limit of 3kB, so make sure you’re not updating the metaData with an object that’s too large.

 

Updating a member returns the updated member’s object.

 

Deleting a member

Developers can delete a member by making a DELETE request to the API member’s endpoint with the corresponding member’s id. The rate limit is 60 requests per second.

const fetch = require('node-fetch')


async function deleteMember() {
const res = await fetch("https://api.memberstack.com/v1/members/3jk90", {
method: "DELETE",
headers: { "X-API-KEY": "..." }
});

const data = await res.json();
console.log(data);
}

 

If a member has been deleted successfully, a status code of 200 with a { success: true } gets returned.

 

The beta API is only the first step in making Memberstack more developer-friendly! Over time, we’ll add more endpoints and possibilities to programmatically interact with your websites, members, and plans.

 

Keywords: Back-end API, backend, etc.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.