'How to get parent folder for a subfolder in Autodesk BIM360 using Forge and Nodejs

I am looking into getting Parent Folder data for subfolders in BIM 360 using Nodejs and Forge

I see the method in Forge GET https://developer.api.autodesk.com/data/v1/projects/:project_id/folders/:folder_id/parent

How to implement this code similar to the GetItemDetails:

async function getItemInfo(client, projectId, itemId) {
 var itemdetails = await client.getItemDetails(projectId, itemId);
 var temp = itemdetails.folder;
 return temp;
 }


Solution 1:[1]

It's quite straightforward.

Find the folder where the item you want is via calling https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-items-item_id-parent-GET/. Here is the code snippet of using Forge nodejs client SDK:

const { FoldersApi, ItemsApi } = require('forge-apis');
const items = new ItemsApi();

const itemParentFolderContents = await items.getItemParentFolder(projectId, itemId, {}, oauthClient, credentials);
 
const itemParentFolderData = itemParentFolderContents.body.data; 

Then you can call the parent folder endpoint you mentioned to get the folder parent of the folder where the item is located at. https://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-parent-GET/ Here is the code snippet of using Forge nodejs client SDK:

const folders = new FoldersApi();
const parentFolderContents = await folders.getFolderParent(projectId, itemParentFolderData.id, {}, oauthClient, credentials);
 
const parentFolderData = parentFolderContents.body.data; 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1