Skip to content

Commit

Permalink
add new recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
pballai committed May 14, 2024
1 parent 204f010 commit 05fc312
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
52 changes: 25 additions & 27 deletions sigma-api-recipes/.env
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
# Provide your Sigma REST API Credentials and URLs below.
# NOTE: Leave no space after the equal sign for each item.
# Information on creating these can be found here: https://help.sigmacomputing.com/reference/explanation

# AWS
CLIENT_ID=
SECRET=
# AWS - PROD:
CLIENT_ID=77d4c471039afe98aedb19c6c4d8019bc47428396c4d73b9a4e5394a4d29b8f0
SECRET=31b7f33798a5cccc1914a3f8b078b149bcb5f31fafbb22ccb8c276e5716505ed16c043241481129c0a08128fd81b359ab42b8c6031b48f37cb86b9ca26c2f856
authURL=https://aws-api.sigmacomputing.com/v2/auth/token
baseURL=https://aws-api.sigmacomputing.com/v2

# API Provider List URLs (if not hosted at AWS US):
#Provider Base URL Token URL
#AWS US https://aws-api.sigmacomputing.com /v2/auth/token
#AWS Canada https://api.ca.aws.sigmacomputing.com /v2/auth/token
#AWS Europe https://api.eu.aws.sigmacomputing.com /v2/auth/token
#AWS UK https://api.uk.aws.sigmacomputing.com /v2/auth/token
#Azure US https://api.us.azure.sigmacomputing.com /v2/auth/token
#GCP https://api.sigmacomputing.com /v2/auth/token
# Papercrane:
#CLIENT_ID=8a3b1efbcea7365d99b9318ec787f9c0aa2d8b00236ece0dd0925193c556123f
#SECRET=f5f7378eaffbb221781a877e8b36627d1841168e92fb7b884499e4771ae7eec8a7a1b65c3d1b072833757fd9830560adb440825d1be66f21f6d7dd53b3a42332
#authURL=https://api.sigmacomputing.com/v2/auth/token
#baseURL=https://api.sigmacomputing.com/v2

# Use-Case Variables, added as required in QuickStart Recipes:
MEMBERID=
NEW_MEMBER_TYPE=

EMAIL=
# Use-Case Variables, added as required in QuickStart use-cases:
MEMBERID=bbV5WjlWMPo4eohIwR2EFzrek4gS8
NEW_MEMBER_TYPE=Viewer

NEW_MEMBER_FIRST_NAME=
NEW_MEMBER_LAST_NAME=
EMAIL=[email protected]
NEW_MEMBER_FIRST_NAME=API
NEW_MEMBER_LAST_NAME=Generated

WORKSPACEID=
TEAMID=
CONNECTIONID=
WORKSPACEID=0719f59c-667d-45f1-a035-7a0d45d9fa19
TEAMID=25d48b2e-b36b-4db2-98a9-2c474f4144da
CONNECTIONID=3d0f0796-87a1-4c1f-b3f0-d85f7ae70bdb

WORKBOOK_ID=
ELEMENT_ID=
WORKBOOK_ID=yloMnddxjJCqL4ZPRdZh3 # API Testing Workbook
# WORKBOOK_ID=5BLZNWQLYOoPMrGqOuN8NR # Plugs Sale Performance Workbook
ELEMENT_ID=TVCujHdvCS

TAGVALUE=
TAGNAME=
FILENAME=
FILEPATH=
TAGVALUE=Staging
TAGNAME=Staging
FILENAME=Staging
FILEPATH=Sales_People
53 changes: 53 additions & 0 deletions sigma-api-recipes/members/get-member-details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This script retrieves the member name for the specified memberID in .env

// This script retrieves the details of a specific member based on memberId

// 1: Load environment variables from a specific .env file for configuration
require('dotenv').config({ path: 'sigma-api-recipes/.env' });

// 2: Import the function to obtain a bearer token from the authenticate-bearer module
const getBearerToken = require('../get-access-token');

// 3: Import Axios for making HTTP requests
const axios = require('axios');

// 4: Load use-case specific variables from environment variables
const baseURL = process.env.baseURL; // Your base URL
const memberId = process.env.MEMBERID; // The specific memberId to find

// Define an asynchronous function to get member details.
async function getMemberDetails() {
// Obtain a bearer token using the previously imported function.
const accessToken = await getBearerToken();
// If unable to obtain a token, log an error message and exit the function.
if (!accessToken) {
console.log('Failed to obtain Bearer token.');
return;
}

try {
// Construct the URL for accessing the API endpoint that retrieves member details.
const memberURL = `${baseURL}/members/${memberId}`;

// Make a GET request to the specified URL, including the bearer token in the request headers for authentication.
const response = await axios.get(memberURL, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Accept': 'application/json'
}
});

console.log(`URL sent to Sigma: ${memberURL}`); // Log the constructed URL before sending the request

// Log the fetched member details to the console in a readable JSON format.
const memberDetails = response.data;
console.log("Member Details:", JSON.stringify(memberDetails, null, 2));

} catch (error) {
// If the request fails, log the error details.
console.error('Error retrieving member details:', error.response ? error.response.data : error);
}
}

// Execute the function to get member details.
getMemberDetails();
2 changes: 1 addition & 1 deletion sigma-api-recipes/members/list-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This script lists all members
// This script returns all members

// 1: Load environment variables from a specific .env file for configuration
require('dotenv').config({ path: 'sigma-api-recipes/.env' });
Expand Down
2 changes: 1 addition & 1 deletion sigma-api-recipes/workbooks/all-input-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function fetchElementsOfWorkbook(workbook, accessToken) {
console.log(`Workbook: "${workbook.name}", Path: "${workbook.path}/${workbook.workbookId}", Page: "${page.name}"`);
inputTableElements.forEach(element => {
// Log details for each 'input-table' element
console.log(` - Input Table: ${element.name}, Element ID: ${element.elementId}`);
console.log(` - Input Table: ${element.name}, Element ID: ${element.elementId}, Latest Version: ${workbook.latestVersion}`);
});
}
} catch (error) {
Expand Down

0 comments on commit 05fc312

Please sign in to comment.