iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐈
Fetching Device Lists from bundle
Introduction
To notify users with outdated OS versions, I retrieve a device list (PCs, smartphones) from bundle and paste it all into a spreadsheet.
Also, bundle is convenient because it can import device information from multiple MDMs such as LANSCOPE and Intune. If you don't have a device master list prepared, you can use bundle as your device master as it is.
In fact, I'd like to use bundle because it allows uploading photos, but I've given up on that for now since our PC failure workflow and PC contract master are already linked to the existing device master.
Code
bundle.js
const TOKEN = PropertiesService.getScriptProperties().getProperty('token');
const URL_API = 'https://xxxxxxxxxxxxxxx.bundle.jp/api/v1';
function fetchBundle(query){
const options = {
'method': 'POST',
'payload': JSON.stringify({query: query}),
'headers': {
'content-type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${TOKEN}`,
},
muteHttpExceptions:true,
};
const res = UrlFetchApp.fetch(URL_API, options);
return JSON.parse(res).data.team;
}
function getAssetList() {
let assetList = [];
let cursor = '';
let json = {};
do{
const query = `
{
team {
assets(first:100, after:"${cursor}"){
pageInfo {
endCursor
hasNextPage
},
nodes{
serialNumber,
assetCategory{
name
}
assetAttributeValues{
... on AssetAttributeValueString {
stringValue
}
assetAttribute{
name,
id
}
}
}
}
}
}
`;
json = fetchBundle(query);
assetList = assetList.concat(json.assets.nodes.map(json => new Asset(json)));
cursor = json.assets.pageInfo.endCursor;
Utilities.sleep(1 * 1000);
}while (json.assets.pageInfo.hasNextPage);
return assetList;
}
Asset.js
class Asset {
constructor(json) {
this.serialNumber = json.serialNumber;
const isLanscope = json.assetCategory.name.includes('LANSCOPE');
const getAttributeValue = name => json.assetAttributeValues.find(attr => attr.assetAttribute.name === name).stringValue;
this.type = getAttributeValue(isLanscope ? 'LANSCOPE_OSタイプ' : 'INTUNE_OS');
this.osVersion = getAttributeValue(isLanscope ? 'LANSCOPE_OSバージョン' : 'INTUNE_OSバージョン');
}
getOutList() {
return [
this.serialNumber,
this.type,
this.osVersion
];
}
}
Results

From here, I will proceed to notify those with outdated versions.
If you have users linked in bundle, it might be a good idea to retrieve user information as well.
Discussion