How to Get a Member ID

Article author
Duncan Hamra
  • Updated

There are a few different ways to get the ID of a member. You can do it manually via the Memberstack dashboard, in the front end using a data attribute, or programmatically via our APIs. This article covers all three methods in order. 

View a Member's ID in the Dashboard

1. Select the member in your Memberstack Dashboard.
2. Under "Profile" the top field is the Member ID. 

member_id_in_the_dashboard.jpg

Get a Member ID using Data Attributes

1. Create a div, text element, or input on your site.
2. Give the element a data attribute of data-ms-member="id"

You can use this attribute to submit an ID via form, to use it in your code, or to display it to a member. 

Get a Member ID from the Member Object

When a member is logged in, you have access to the "Member Object" in the front end. The object will look something like this (starting with the Member ID):

{
  data: {
    id: "mem...",
    auth: {
      email: "john@doe.com",
      hasPassword: true,
      providers: []
    },
    customFields: {
      country: "Germany"
    },
    metaData: {
      avatar: "photo.png"
    },
    permissions: ["view:basic:workouts"],
    planConnections: [{
      id: "con_...",
      status: "ACTIVE"
      planId: "pln_...",
      type: "FREE",
      payment: null
    }],
    verified: true
  }
}

 

You can also get the id directly using this code.


MemberStack.onReady.then(function(member) {   
if (member.loggedIn) {
	var id = member["id"]
	// do something with the id
}
})

Keywords: current user ID, userID, memberID, memberstackid, 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.