Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello guys
I have script to get all the sheets even private content from Qlik SaaS
and i getting this error:
..\\node_modules\enigma.js\enigma.js:2461
var error = new Error(data.message);
^
Error: Access denied
at Intercept.errorResponseInterceptor (..\node_modules\enigma.js\enigma.js:2461:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async GetSheets (file:/../ProjectQlikApi/TestingListSheets.mjs:62:15)
at async file://../ProjectQlikApi/TestingListSheets.mjs:53:9 {
code: 5,
parameter: ''
}
I'm use this code bellow:
Import { auth, users, items } from "@qlik/api";
const hostConfig = {
host: "XXXXXXXXXXXXX",
authType: "oauth2",
clientId: "XXXXXXXXXXXXX",
clientSecret: "XXXXXXXXXXXXX",
scope: "user_default admin.apps admin_classic",
};
const csvFilePath = "output.csv";
// Helper function to write to CSV
function writeToCsv(data) {
fs.appendFileSync(csvFilePath, data + '\n', 'utf8');
}
(async () => {
auth.setDefaultHostConfig(hostConfig);
//get apps in personal spaces
const itemList = await items
.getItems({
resourceType: "app",
spaceType: "managed",
spaceId: "To Filter one Space only ( i change this vlaue here)"
limit: 100,
})
.then((res) => {
return res.data;
});
//use a promise to return a new array of apps containing the app owner's name
let appList = await Promise.all(
itemList.data.map(async (item) => {
return {
id: item.id,
resourceId: item.resourceId,
name: item.name,
ownerId: item.ownerId,
ownerName: await getUserName(item.ownerId),
};
}),
);
// Add header to the CSV file
writeToCsv("AppName,AppID,ObjectType,Name,ObjectID,Owner,Created_date,Publish_Status");
for (let app of appList)
{
console.log(app.name);
await GetSheets(app);
await GetBookmarks(app);
}
process.exit();
})();
//helper function that returns a name for the supplied userId
async function getUserName(userId) {
const user = await users.getUser(userId);
return user.data.name;
}
async function GetSheets(appmeta) {
console.error(appmeta.AppId);
const app = await qix.openAppSession(appmeta.AppId).getDoc();
const sheets = await app.getSheetList();
for (let sheet of sheets) {
writeToCsv(`${appmeta.name},${appmeta.AppId},Sheet,${sheet.qMeta.title},${sheet.qMeta.id},${sheet.qMeta.owner},${sheet.qMeta.createdDate},${sheet.qMeta.published}`);
//writeToCsv(`${appmeta.name},${appmeta.AppId},Sheet,${sheet.qMeta.title},${sheet.qMeta.owner},${sheet.qMeta.createdDate},${sheet.qMeta.published}`);
}
}
async function GetBookmarks(appmeta) {
console.error(appmeta.AppId);
const app = await qix.openAppSession(appmeta.AppId).getDoc();
const bookmarks = await app.getBookmarkList();
for (let bookmark of bookmarks) {
//console.log(bookmarks);
//writeToCsv(`${appmeta.name},${appmeta.AppId},Bookmark,${bookmark.qMeta.title},${bookmark.qMeta.owner},${bookmark.qMeta.createdDate},${bookmark.qMeta.published}`);
writeToCsv(`${appmeta.name},${appmeta.AppId},Bookmark,${bookmark.qMeta.title},${bookmark.qMeta.id},${bookmark.qMeta.owner},${bookmark.qMeta.createdDate},${bookmark.qMeta.published}`);
}
}
What i can understand is i getting Access Denied, because the QlikBot\something, doesn't have access to the aplication, i would like to impersonate another person, like myself, does anyone knows how to do this ?
It solved,
Seems you need to and into the session access your Qlikbot and works fine
It solved,
Seems you need to and into the session access your Qlikbot and works fine