Front-End API Instructions

Caution: This guide is for people who have JavaScript experience

This article will cover three topics

Accessing member information with JS
Updating member profile information with JS
Updating and retrieving member metadata.

How to access member information with JS

MemberStack.onReady.then(function(member) {
// do things with the member object
member["email"]
member["name"]

// unique identifier for the member
member["id"]

// member's specific page if set.
member.memberPage

// check if member is logged in
member.loggedIn // returns true or false
})


You have access to any fields you collect during signup, just like you do when using ms-data.

You can also access the member's membership info.

MemberStack.onReady.then(function(member) {

var membership = member.membership

membership.id // current membership
membership.status // active, canceled, past_due, unpaid, trialing
membership.current_period_end // unix timestamp
membership.cancel_at_period_end // true or false

})


The current period end is a unix timestamp. Here's an example on how to convert it into a date object.

var date = new Date(membership.current_period_end * 1000)

Updating member profile information with JS

The updateProfile method accepts two arguments. The first argument is an object containing the data you would like to update. The key's must match your form field values given in your MemberStack dashboard. The second argument is a boolean value. If set to true, MemberStack will show a loader and default success/error messages. If false, MemberStack will silently update the profile with no loaders or success/error messages.

MemberStack.onReady.then(function(member) {

member.updateProfile({
"first-name": "Dave",
"last-name": "Mathews"
}, false)

})


You can use then and catch to know when the update is done and to handle errors.

Updating and retrieving member metadata

MemberStack allows you to extend its functionality through member metadata. You have the ability to update and access metadata that you can store with each Member

Metadata must be valid JSON

Updating

To set/update metadata use the updateMetaData member function.

MemberStack.onReady.then(function(member) {
var memberProgress = {
lesson1: "finished",
lesson2: "in-progress"
}
member.updateMetaData(memberProgress)
})

You can update a single property without affecting others.

lesson1 data will not be changed

MemberStack.onReady.then(function(member) {
var memberProgress = {
lesson2: "finished"
}
member.updateMetaData(memberProgress)
})


You can remove properties by setting their value to null

lesson1 and lesson2 data will removed

MemberStack.onReady.then(function(member) {
var memberProgress = {
lesson1: null,
lesson2: null
}
member.updateMetaData(memberProgress)
})


Retrieving

MemberStack.onReady.then(async function(member) {
var metadata = await member.getMetaData()
// do stuff with members data
})
Was this article helpful?
Cancel
Thank you!