Workbooks - Update owner (Javascript)

View as Markdown

This script updates the ownership of a specific workbook by workbookId.

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

Example script

Node
1// This script updates the ownership of a specified inode in Sigma using the "Update an inode" endpoint.
2
3// Load environment variables from a specific .env file for configuration
4require('dotenv').config({ path: 'sigma-api-recipes/.env' });
5
6// Import the function to obtain a bearer token from the authenticate-bearer module
7const getBearerToken = require('../get-access-token');
8
9// Import Axios for making HTTP requests
10const axios = require('axios');
11
12// Load use-case specific variables from environment variables
13const baseURL = process.env.baseURL; // Base URL for the Sigma API
14const memberid = process.env.MEMBERID; // New member ID to assign to the inode as owner
15const workbookId = process.env.WORKBOOK_ID; // Workbook ID to be used as the urlId for the inode
16
17// Function to update the ownerId of a specified inode using the workbookId
18async function updateInodeOwner(workbookId) {
19 const token = await getBearerToken();
20 if (!token) {
21 console.error('Failed to obtain Bearer token.');
22 return;
23 }
24
25 try {
26 const response = await axios.patch(
27 `${baseURL}/files/${workbookId}`,
28 { ownerId: memberid }, // Use `ownerId` with `memberid` value from .env
29 {
30 headers: {
31 'Authorization': `Bearer ${token}`,
32 'Content-Type': 'application/json'
33 }
34 }
35 );
36 console.log('Inode updated successfully:', response.data);
37 } catch (error) {
38 console.error('Error updating inode:', error.response ? error.response.data : error);
39 }
40}
41
42// Execute the update function
43updateInodeOwner(workbookId);
Response Example
1Inode updated successfully

Endpoints used

  1. Get authentication token: getBearerToken function
  2. Update an inode: /files/{inodeId}