I was working on some webmap JSON massaging piece of code and wanted to get to the JSON of a Portal item. Looks like 4.x has a PortalItem class. But the closest I could there with 3.x was this:
define([...,
"esri/arcgis/Portal",
"esri/request"
],
function(...,
arcgisPortal,
esriRequest)}
...
let portal = new arcgisPortal.Portal('https://my-super-awesome-portal');
let itemParams = {
q: 'id: gobbledeegobbledeegook'
};
portal.queryItems(itemParams)
.then(function(result){
let itemDataUrl = result.results[0].itemDataUrl;
let request = esriRequest({
url: itemDataUrl,
content: {f: 'json'},
handleAs: 'json',
});
request.then(function(response){
let operationalLayersJSON = response['operationalLayers'];
console.log(JSON.stringify(operationalLayersJSON));
}, function(error) {
console.log("Error: ", error.message);
});
});
Given the differences between 3.x/4.x, is the above the best way to do it? It works. Of course, it relies on me knowing and plugging the item's gobbledeegook ID.
If I'm working in WAB and the item of interest is the current app's Portal web map, then I can use:
this.map.itemId