var myUrl = 'somevalue'; // I know this value at runtime, so not a problem.
var myItemId = 'someOtherValue'; // Ditto.
var thisPortal = new arcgisPortal.Portal(myurl);
thisPortal.signIn().then(function (loggedInUser) {
var theToken = loggedInUser.credential.token;
loggedInUser.getItem(myItemId).then(function(theItem) {
// I want to add a tag to the item so I know it's ok to automatically toss it a day later.
// then I want to write the item back to the portal.
// I could not find any way to do this in the 3.20 javascript api, so I'm using the restful api.
var tagsCsv = '';
for (var i = 0; i < theItem.tags.length; i++) {
tagsCsv = tagsCsv + theItem.tags + ',';
}
tagsCsv = tagsCsv + 'Delete in One Day';
// I could not find any documentation for the restful api to do this either, but I could observe via the
// browser debugger what the portal did when I manually added a tag to the portal item.
var updateUrl = '{portalUrl}sharing/rest/content/users/{userId}/items/{itemId}/update';
updateUrl = updateUrl.replace('{portalUrl}',myUrl);
updateUrl = updateUrl.replace('{userId}',loggedInUser.username);
updateUrl = updateUrl.replace('{itemId}', theItem.id);
xhr.post(updateUrl, {
data: {
tags: tagsCsv,
clearEmptyFields: 'true',
id: theItem.id,
f: 'json',
token: theToken
}
}).then(function(data) { // officially a success
// inspect and take whatever action you deem fit.
},
function(error) { // officially a failure
// inspect and take whatever action you deem fit.
},
function(evt) { // status notification, works depending on the browser version.
// inspect and take whatever action you deem fit.
});
});
});
I had to transpose this by hand, hopefully it's syntactically correct. If not, post the mistakes and I'll edit it to match.