Admin Package (Node.js) The Memberstack Node.js Admin API allows you to verify webhooks and JWT tokens, and use CRUD methods on Members.
Getting Started
Welcome to the Memberstack Admin Package for Node.js! This guide will help you understand how to effectively utilize our package. It covers critical areas like authentication, rate limits, and how to initialize Memberstack in your Node.js environment.
Authentication
Memberstack's Admin API employs secret keys for request authentication. You can manage these keys from your Memberstack Dashboard. There are two types of secret keys:
Test Mode (sandbox) Secret Keys: These keys start with sk_sb_
. Use these keys when you're testing or developing on your platform.
Live Mode Secret Keys: These keys start with sk_live_
. Use these keys for your production environment.
Rate Limits
Our API allows up to 25 requests per second. If you find this limit constraining, please contact our support team, and we can discuss increasing your rate limit.
Security and Secret Keys
Your secret keys possess administrative privileges; hence, their security is paramount. They should be confined to server-side environments only. Avoid using your secret keys in publicly accessible areas, such as Webflow, GitHub, or any client-side code.
Initializing Memberstack in Node.js
To start using Memberstack in your Node.js environment, follow these steps:
Install the Memberstack Admin Package: You can install the package from the npm public registry or through yarn .
Using npm:
Copy npm install @memberstack/admin
Using yarn:
Copy yarn add @memberstack /admin
Initialize Memberstack: After the successful installation, initialize Memberstack by passing your secret key to the init
method, like so:
Copy import memberstackAdmin from "@memberstack/admin" ;
const memberstack = memberstackAdmin .init ( "sk_..." );
That's it! You're now ready to explore the powerful features of the Memberstack Admin Package in your Node.js environment.
Actions
List all membersList all members connected to your application.
Parameters :
after number
The endCursor
after which the querying should start.
order ASC | DESC
The order in which the members should be queried. Default: ASC
limit number
The maximum amount of members to query. Default: 50
Request Example :
Copy await memberstack . members .list ();
await memberstack . members .list ({
after : 2458433 ,
limit : 5 ,
order : "DESC"
});
Response :
totalCount number
The total amount of queryable members
endCursor number
The endCursor
of the last queried member
hasNextPage boolean
Indicator showing whether there are more members to query
data boolean
List of queried members
Response Example :
Copy {
totalCount : 2 ,
endCursor : 456 ,
hasNextPage : false ,
data : [
{
id : "mem_..." ,
createdAt : "2022-05-19T18:57:35.143Z" ,
lastLogin : "2022-05-19T18:57:35.143Z" ,
auth : {
email : "john@doe.com"
} ,
customFields : {
country : "Germany"
} ,
metaData : {
avatar : "photo.png"
} ,
loginRedirect : "/john-welcome" ,
permissions : [ "view:basic:workouts" ] ,
planConnections : [
{
id : "con_..." ,
status : "ACTIVE"
planId: "pln_..." ,
type : "FREE" ,
payment : null
} ,
]
} ,
{
id : "mem..." ,
createdAt : "2021-04-20T18:57:35.143Z" ,
lastLogin : "2022-05-19T18:57:35.143Z" ,
auth : {
email : "jane@doe.com"
} ,
customFields : {
country : "USA"
} ,
metaData : {
avatar : "photo2.png"
} ,
loginRedirect : "/jane-welcome" ,
permissions : [ "view:all:workouts" ] ,
planConnections : [
{
id : "con_..." ,
status : "ACTIVE"
planId: "pln_..." ,
type : "FREE" ,
payment : null
} ,
]
} ,
]
}
Retrieve a memberRetrieve a member by their id or email
Parameters :
id string
The id
of the member to retrieve
OR
email string
The email
of the member to retrieve
Request Example :
Copy await memberstack . members .retrieve ({
id : "mem_..."
});
Copy await memberstack . members .retrieve ({
email : "members-email@test.com"
});
Response :
data object
The Member
object
Response Example :
Copy {
data : {
"id" : "mem_sb_cl3ddkq070005njvl997d9mf8" ,
"auth" : {
"email" : "user-1652986650386@test.com"
} ,
"createdAt" : "2022-05-19T18:57:35.143Z" ,
"lastLogin" : "2022-05-19T18:57:35.143Z" ,
"metaData" : {
"language" : "Swedish"
} ,
"customFields" : {
country : "Sweden"
} ,
"permissions" : [ "per_basic" ] ,
"loginRedirect" : "login-redirect-1" ,
"planConnections" : [{
"id" : "con_cl3ddkq060004njvl2zx6cnub" ,
"active" : true ,
"status" : "ACTIVE" ,
"planId" : "pln_sb_cl3d9q5yi00040tczdir41rsy" ,
"planName" : "My Awesome Free Plan" ,
"type" : "FREE" ,
"payment" : null
}]
}
}
Create a memberCreate a member connected to a free plan.
Parameters :
email required string
The member's email
password required string
The member's password
plans array
Optional for free plans. An array of planId
objects.
[{"planId": "pln_abc"}]
customFields object
Optional custom fields.
metaData object
Optional metadata object.
json object
Optional json object.
loginRedirect string
Optional loginRedirect
Request Example :
Copy await memberstack . members .create ({
email : "john2@doe.com" ,
password : "123123123" ,
plans : [
{
"planId" : "pln_abc123"
}
] ,
customFields : {
country : "Sweden"
} ,
json : {
friends : [ "mem_123..." , "mem_456..." ]
} ,
metaData : {
language : "Swedish"
} ,
loginRedirect : "/welcome"
});
Response :
data object
The Member
object
Response Example:
Copy {
data : {
"id" : "mem_sb_cl3ddkq070005njvl997d9mf8" ,
"auth" : {
"email" : "user-1652986650386@test.com"
} ,
"createdAt" : "2022-05-19T18:57:35.143Z" ,
"metaData" : {
"hi" : "there"
} ,
json : {
friends : [ "mem_123..." , "mem_456..." ]
} ,
"customFields" : {
"name" : "Tyler"
} ,
"permissions" : [ "per_basic" ] ,
"loginRedirect" : "login-redirect-1" ,
"planConnections" : [{
"id" : "con_cl3ddkq060004njvl2zx6cnub" ,
"active" : true ,
"status" : "ACTIVE" ,
"planId" : "pln_sb_cl3d9q5yi00040tczdir41rsy" ,
"type" : "FREE" ,
"payment" : null
}]
}
}
Update a memberUpdate a member by their id.
Parameters :
id required string
The id
of the member to update
Request Example :
Copy await memberstack . members .update ({
id : "mem_..." ,
data : {
email : "members-updated-email@test.com"
metaData: {
language : "Swedish"
} ,
customFields : {
country : "Sweden"
} ,
json : {
friends : [ "mem_123..." , "mem_456..." ]
} ,
}
});
Response :
data object
The Member
object
Response Example :
Copy {
data: {
"id": "mem_sb_cl3ddkq070005njvl997d9mf8",
"auth": {
"email": "user-1652986650386@test.com"
},
"createdAt": "2022-05-19T18:57:35.143Z",
"metaData": {
"language": "Swedish"
},
"customFields": {
country: "Sweden"
}
"permissions": ["per_basic"],
"loginRedirect": "login-redirect-1",
"planConnections": [{
"id": "con_cl3ddkq060004njvl2zx6cnub",
"active": true,
"status": "ACTIVE",
"planId": "pln_sb_cl3d9q5yi00040tczdir41rsy",
"type": "FREE",
"payment": null
}]
}
}
Delete a memberDelete a member by their id.
Parameters :
id required string
The id
of the member to delete
Request Example :
Copy await memberstack . members .delete ({
id : "mem_..." ,
});
Response :
data string
The deleted member's
id.
Response Example :
Copy {
data : {
"id" : "mem_..."
}
}
Add a free plan to a memberAdd a free plan to a member.
Parameters :
planId required string
The planId
of the plan to add
Request Example :
Copy await memberstack . members .addFreePlan ({
id : "mem_..." ,
data : {
planId : "pln_abc"
}
});
Response :
Remove a free plan from a memberRemove a free plan from a member.
Parameters:
planId required string
The planId
of the plan to remove
Request Example :
Copy await memberstack . members .removeFreePlan ({
id : "mem_..." ,
data : {
planId : "pln_abc"
}
});
Response :
Verification
Webhook & JWT verification methods cannot be performed via REST API at the moment.
Verify member tokenVerify the integrity and retrieve the payload of a member token.
Request Example :
Copy await memberstack .verifyToken ({
token : "ey...." ,
audience : "app_...."
});
or you can also pass in an optional audience parameter.
Copy await memberstack .verifyToken ({
token : "ey...." ,
audience : "app_...."
});
Parameters :
token required string
The member's token
audience string
optional Your app's id
for aud
(audience) verification. By default, Memberstack only verifies the iss
(issuer) and the exp
(expiration) of the token.
Response :
id string
The member's id
type string
The type of resource for which this token was created. member
Response Example :
Copy {
id : "mem..." ,
type : "member" ,
iat : 1633486880169 ,
exp : 1633486880369
iss : "https://api.memberstack.com" ,
aud : "app_..." ,
}
Verify webhook signatureVerify the integrity of a webhook.
Request Example :
Copy const isValid = memberstack .verifyWebhookSignature ({
headers : req .headers ,
secret : "websec_..." ,
payload : req . body .payload ,
tolerance : 300
});
Parameters :
headers required object The request headers.
secret required string
The webhook's signing secret (found in Webhook settings on the dashboard)
payload required object
The event's payload
tolerance number
The time tolerance for the webhook in seconds. (default: 300)
Response :
boolean
true
if the signature matches the payload and time tolerance