Memberstack Admin Package (REST)

Article author
Josh Lopez
  • Updated

The Memberstack REST Admin API allows you to perform full CRUD (create, read, update, delete) operations on members as well as verify webhooks and JWT tokens programmatically in your JavaScript application. This enables you to build custom admin panels, sync members with external databases, integrate with third-party services, and more. The Admin API uses standard REST conventions with JSON request and response bodies, making it easy to use with any JavaScript HTTP client like axios or the native fetch API.

View the full Admin Package Guide for more additional guidance. 

Getting Started

Authentication

The Admin REST Package uses secret API keys to authenticate requests. You can find your API keys in your Memberstack app on the Dev Tools page.

Use your sk_sb_... key for development and sk_... in production.

Here's an example using axios to authenticate requests:

const apiKey = process.env.MEMBERSTACK_API_KEY; 
const headers = { "X-API-KEY": apiKey }; 
const axios = require('axios'); 
axios.get('https://admin.memberstack.com/members', {headers});

Rate Limits - 25 requests per second. Contact support if you need this increased.

Security - Keep your secret keys secure and use only in server-side code, not client-side.

Base URL

The base URL for all requests is:

 https://admin.memberstack.com 

Actions

List Members

Get a paginated list of members:

const url = 'https://admin.memberstack.com/members'; 
axios.get(url, {headers}).then(res => { 
  console.log(res.data); 
});

Optional parameters:

  • after - Pagination cursor
  • order - ASC or DESC
  • limit - Max number to return (default 50)

Get a Member

Get a member by id:

const memberId = 'mem_1234'; 
const url = `https://admin.memberstack.com/members/${memberId}`; 
axios.get(url, {headers}).then(res => { 
  console.log(res.data); 
});

Or by email:

const email = 'john@doe.com'; 
const encodedEmail = encodeURIComponent(email); 
const url = `https://admin.memberstack.com/members/${encodedEmail}`; 
axios.get(url, {headers}).then(res => { 
  console.log(res.data); 
});

Create a Member

const url = 'https://admin.memberstack.com/members'; 
const data = { 
  email: 'john@doe.com', 
  password: 'password123', 
  plans: [{planId: 'pln_1234'}], 
}; 
axios.post(url, data, {headers}).then(res => { 
  console.log(res.data); 
  // Created member 
});

Required parameters:

  • email - The member's email
  • password - The member's password

Optional parameters:

  • plans - Free plans only. Array of planId objects. [{"planId": "pln_abc"}]
  • customFields - Object of custom fields.
  • metaData - Metadata object.
  • json - JSON object.
  • loginRedirect - loginRedirect string.

Update a Member

const memberId = 'mem_1234'; 
const url = `https://admin.memberstack.com/members/${memberId}`; 
const data = { 
  customFields: { 
    country: 'Sweden' 
  } 
}; 
axios.patch(url, data, {headers}).then(res => { 
  console.log(res.data); 
  // Updated member 
});

Delete a Member

const memberId = 'mem_1234'; 
const url = `https://admin.memberstack.com/members/${memberId}`; 
axios.delete(url, {headers}).then(res => { 
  console.log(res.data); 
  // Deleted member ID 
});

Add/Remove Free Plans

const memberId = 'mem_1234'; 

// Add plan 
const url = `https://admin.memberstack.com/members/${memberId}/add-plan`; 
axios.post(url, {planId: 'pln_4567'}, {headers}); 

// Remove plan 
const url = `https://admin.memberstack.com/members/${memberId}/remove-plan`; 
axios.post(url, {planId: 'pln_4567'}, {headers});

Verify a Token

const url = 'https://admin.memberstack.com/members/verify-token'; 
axios.post(url, {token: 'jwt_token'}, {headers}).then(res => { 
  console.log(res.data); 
  // Verified member 
})

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.