Member - Get Member Details (JavaScript)

View as Markdown

This script retrieves the details of a specific member based on the memberId or email provided in the .env file.

Refer to the Sigma REST API Recipes QuickStart for step-by-step instructions.

Example script

JavaScript
1// get-member-details.js
2// This script retrieves the details of a specific member based on EMAIL or MEMBERID.
3
4// 1: Load environment variables from a specific .env file for configuration
5require('dotenv').config({ path: 'sigma-api-recipes/.env' });
6
7// 2: Import the function to obtain a bearer token from the authenticate-bearer module
8const getBearerToken = require('../get-access-token');
9
10// 3: Import Axios for making HTTP requests
11const axios = require('axios');
12
13// 4: Load use-case specific variables from environment variables
14const baseURL = process.env.baseURL; // Your base URL
15const memberId = process.env.MEMBERID; // Member ID, if provided
16const email = process.env.EMAIL; // Email, if provided
17
18// Define an asynchronous function to get member details.
19async function getMemberDetails() {
20 // Obtain a bearer token using the previously imported function.
21 const accessToken = await getBearerToken();
22 // If unable to obtain a token, log an error message and exit the function.
23 if (!accessToken) {
24 console.log('Failed to obtain Bearer token.');
25 return;
26 }
27
28 // Determine whether to use MEMBERID or EMAIL
29 let memberURL;
30 if (memberId) {
31 memberURL = `${baseURL}/members/${memberId}`;
32 console.log(`Fetching member details by MEMBERID: ${memberId}`);
33 } else if (email) {
34 memberURL = `${baseURL}/members?search=${encodeURIComponent(email)}`;
35 console.log(`Fetching member details by EMAIL: ${email}`);
36 } else {
37 console.error('Neither MEMBERID nor EMAIL is provided in the .env file.');
38 return;
39 }
40
41 try {
42 // Make a GET request to the specified URL, including the bearer token in the request headers for authentication.
43 const response = await axios.get(memberURL, {
44 headers: {
45 'Authorization': `Bearer ${accessToken}`,
46 'Accept': 'application/json'
47 }
48 });
49
50 console.log(`URL sent to Sigma: ${memberURL}`); // Log the constructed URL before sending the request
51
52 // Log the fetched member details to the console in a readable JSON format.
53 const memberDetails = response.data;
54 console.log("Member Details:", JSON.stringify(memberDetails, null, 2));
55
56 } catch (error) {
57 // If the request fails, log the error details.
58 console.error('Error retrieving member details:', error.response ? error.response.data : error.message);
59 }
60}
61
62// Execute the function to get member details.
63getMemberDetails();
Response Example
1Member Details: {
2 "organizationId": "adbfe832-733a-4c83-b64d-bdbf6ae8d2cb",
3 "memberId": "bbV5WjlWMPo4eohIwR2EFzrek4gS8",
4 "memberType": "Creator",
5 "firstName": "firstname of member",
6 "lastName": "lastname of member",
7 "email": "member@test.com",
8 "profileImgUrl": null,
9 "createdBy": "bbV5WjlWMPo4eohIwR2EFzrek4gS8",
10 "updatedBy": "yRn1UFV8ngVWBM1Hgrl51h7MS8uow",
11 "createdAt": "2023-12-06T22:36:51.191Z",
12 "updatedAt": "2024-03-26T14:09:01.464Z",
13 "homeFolderId": "6ea2a4a2-f121-4dc3-8b36-2343dace8876",
14 "userKind": "internal",
15 "isArchived": false,
16 "isInactive": false
17}

Endpoints used

  1. Get authentication token: getBearerToken function
  2. Get member details: ${baseURL}/members/${memberId}