Using Memberstack 2.0? There is an updated version of this article here.
The Memberstack API makes it possible for users to retrieve, update, or delete data connected to their websites.
Note: The Memberstack API Beta currently only allows the modification of a website's members.
Important: This is not a front-end API and should only be used in the backend.
Authentication
The Memberstack API uses an API key to authenticate the requests. You can retrieve an API key in the Memberstack dashboard.
The received API key can be added to the X-API-KEY request header.
Javascript:
fetch('https://api.memberstack.com/v1/members', {
headers: {
'X-API-KEY': // your API key
}
})
Curl:
curl -i -H "X-API-KEY: yourapikey" -H "Content-Type: application/json" https://api.memberstack.com/v1/members
Note: Make sure you're not exposing your private API key in a browser environment.
Member Endpoints
The typical response contains the member object, or an array of member objects. The member object contains the following fields:
Key | Value |
id | Unique identifier of user. |
membership | Membership Object (below) |
Email address of user | |
createdAt | Date when user signed up. |
stripeInfo (Optional) | Gets returned if the user has a stripe account. |
metaData (Optional) | Gets returned if user contains meta data. |
Membership Object
Key | Value |
oneTime | Boolean |
testMode | Boolean |
status | trialing| active| expired | past_due| canceled unpaid | incomplete| incomplete_expired |
plan | String. Unique identifier of plan. |
type | free | paid |
cancel_at_period_end | Boolean |
current_period_end | String. Unix Timestamp |
amount | Integer. Cost of plan in cents. |
customer | Unique identifier of Stripe's customer id |
card |
payment_method: Unique identifier of Stripe's payment method. source*: Unique identifier of Stripe's source method. brand: Card brand. American Express | Discover | MasterCard | Visa exp_month: Card's expiration month. exp_year: Card's expiration year. last4: Card's last four digits. |
Note: Source has been deprecated in favor of payment_method and is only available on older members.
List Members
List all members that have a subscription to your website.
Other query parameters include limit to limit the amount of objects that get returned and page that gets the next batch of objects.
Javascript:
fetch('https://api.memberstack.com/v1/members', {
headers: {
'X-API-KEY': 'yourapikey'
}
}
Curl:
curl -i -H "X-API-KEY: yourapikey" -H "Content-Type: application/json" https://api.memberstack.com/v1/members
Get Member
Javascript:
fetch('https://api.memberstack.com/v1/members/123', {
headers: {
'X-API-KEY': 'yourapikey'
}
}
Curl:
curl -i -H "X-API-KEY: yourapikey" -H "Content-Type: application/json" https://api.memberstack.com/v1/members/123
Create Member
Important: We currently only allow the creation of new members for free plans.
Note: metaData can contain up to 50 values. Object keys cannot be longer than 50 characters, object values cannot be longer than 500 characters.
Note: When creating a member please make sure the email is all lowercase.
Javascript:
fetch('https://api.memberstack.com/v1/members', {
method: 'POST',
headers: {
'X-API-KEY': 'yourapikey'
},
body: JSON.stringify({
email: "...",
password: "...",
plan: "...",
customFields: {
userName: "...",
avatar: "..."
}
})
}
Curl:
curl -XPOST -H 'X-API-KEY: yourapikey' -d '{
email: "...",
password: "...",
plan: "...",
customFields: {
userName: "...",
avatar: "..."
}
}' 'https://api.memberstack.com/v1/members'
You can get the id of a plan by going to memberships in the dashboard, and extracting the id from the signup link.
Update Member
Note: metaData can contain up to 50 values. Object keys cannot be longer than 50 characters, object values cannot be longer than 500 characters.
Javascript:
fetch('https://api.memberstack.com/v1/members/123', {
method: 'POST',
headers: {
'X-API-KEY': 'yourapikey'
},
body: JSON.stringify({
email: "...",
password: "...",
})
}
Curl:
curl -XPOST -H 'X-API-KEY: yourapikey' -d '{
email: "...",
password: "..."
}' 'https://api.memberstack.com/v1/members/123'
Delete Member
Javascript:
fetch('https://api.memberstack.com/v1/members/123', {
method: 'DELETE',
headers: {
'X-API-KEY': 'yourapikey'
}
}
Curl:
curl -XDELETE -H 'X-API-KEY: yourapikey' https://api.memberstack.com/v1/members/123
Live Example
Interact instantly with the API in this Codesandbox embed. In order to be able to use the API endpoints, you'll need to:
- Update the value of API_KEY with the value of your API key.
- Update the value of FREE_PLAN_ID with the id of a free plan on your website. You can get the id of a plan by going to memberships in the dashboard, and extracting the id from the signup link.
- Update the values of the USER_ID_TO_FETCH for the user that will be queried, USER_ID_TO_UPDATE for the user that will be updated, and USER_ID_TO_DELETE for the user that will be deleted.
Note: These values can be the same id. Deleting the user with the id of USER_ID_TO_DELETE will be removed permanently.
Comments
0 comments
Please sign in to leave a comment.