Skip to content
import PortalUser from "@arcgis/core/portal/PortalUser.js";
Inheritance:
PortalUserAccessor
Since
ArcGIS Maps SDK for JavaScript 4.0

Represents a registered user of the Portal. Personal details of the user, such as email and groups, are returned only to the user or the administrator of the user's organization. View the ArcGIS Portal API REST documentation for the user for more details.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

access

Property
Type
"private" | "org" | "public" | null | undefined

Indicates the level of access of the user. If private, the user descriptive information will not be available to others nor will the username be searchable.

created

autocast Property
Type
Date | null | undefined

The date the user was created.

culture

Property
Type
string | null | undefined

The culture information for the user.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor
Since
ArcGIS Maps SDK for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

description

Property
Type
string | null | undefined

A description of the user.

email

Property
Type
string | null | undefined

The user's e-mail address.

fullName

Property
Type
string | null | undefined

The user's full name.

id

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 4.33

The unique id for the user.

modified

autocast Property
Type
Date | null | undefined

The date the user was last modified.

orgId

Property
Type
string | null | undefined

The ID of the organization the user belongs to.

portal

Property
Type
Portal

The portal associated with the user.

preferredView

Property
Type
string | null | undefined

The user's preferred view for content, either web or GIS.

privileges

Property
Type
string[]

The user's privileges based on their user type or role in their organization.

region

Property
Type
string | null | undefined

The user preferred region, used to set the featured maps on the home page, content in the gallery, and the default extent of new maps in the Viewer.

role

Property
Type
"org_admin" | "org_publisher" | "org_user" | null | undefined

Defines the user's role in the organization. See roleId for more details about when user has a custom role.

roleId

Property
Type
string | null | undefined

The ID of the user's role. Only set if the user is assigned a custom role.

When present, the role will indicate the "base" role of the custom role based on the privileges the custom role contains. For example, if the custom role contains some publisher privileges, the role will be set to org_publisher.

sourceJSON

Property
Type
any
Since
ArcGIS Maps SDK for JavaScript 4.13

The JSON used to create the property values when the PortalUser is created. Although most commonly used properties are exposed on the PortalUser class directly, this provides access to all information returned for the portal user. This property is useful if working in an application built using an older version of the API which requires access to a portal's user properties from a more recent version.

See also

thumbnailUrl

readonly Property
Type
string | null

The URL to the thumbnail image for the user.

See also

units

Property
Type
"english" | "metric" | null | undefined

The user's personal units of measure setting.

userContentUrl

readonly Property
Type
string | null

The URL for the user's content.

username

Property
Type
string

The username of the user.

Methods

MethodSignatureClass
fromJSON
inherited static
fromJSON(json: any): any
addItem(params: AddItemParameters): Promise<PortalItem>
deleteItem(item: PortalItem, permanentDelete?: boolean): Promise<void>
deleteItems(items: PortalItem[], permanentDelete?: boolean): Promise<DeleteItemsResult[]>
fetchFolders(): Promise<PortalFolder[]>
fetchGroups(): Promise<PortalGroup[]>
fetchItems(params?: FetchItemsParameters): Promise<FetchItemsResult>
fetchTags(): Promise<Array<{ tag: string; count: number; }>>
getThumbnailUrl(width?: number): string | null | undefined
queryFavorites(queryParams?: PortalQueryParamsProperties): Promise<PortalQueryResult<PortalItem>>
restoreItem(item: PortalItem, folder?: PortalFolder | string): Promise<void>
toJSON
inherited
toJSON(): any

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameters
ParameterTypeDescriptionRequired
json
any

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
any

Returns a new instance of this class.

addItem

Method
Signature
addItem (params: AddItemParameters): Promise<PortalItem>

Adds an item to the user's portal content.

Parameters
ParameterTypeDescriptionRequired
params

See the object specifications table below for the parameters that may be passed as properties in this object.

Returns
Promise<PortalItem>

When resolved, returns the PortalItem to be added to the user's content.

deleteItem

Method
Signature
deleteItem (item: PortalItem, permanentDelete?: boolean): Promise<void>

Deletes an item from the user's portal content.

Parameters
ParameterTypeDescriptionRequired
item

The portal item to remove.

permanentDelete

Since 4.30. When the recycle bin is enabled and the item to be deleted is an item type supported by the recycle bin, this parameter determines if the item should be permanently deleted. If true, the item will be permanently deleted. Otherwise, the item will be moved to the recycle bin. If the recycle bin is disabled, this parameter has no effect. If the item is not supported by the recycle bin, it will be permanently deleted regardless of the value of this parameter.

Returns
Promise<void>

Resolves when the item has been deleted from the user's content.

Example
// Delete an item from the user's content.
// This will recycle an item if the recycle bin is enabled and item is supported, or
// permanently delete it if the recycle bin is disabled or not supported.
const portalItem = new PortalItem({
id: "affa021c51944b5694132b2d61fe1057"
});
portal.user.deleteItem(portalItem).then(() => {
console.log("Item deleted from user's content.");
})
// If the item could not be deleted, an error will be returned.
.catch((error) => {
console.error("Error deleting item: ", error);
});

deleteItems

Method
Signature
deleteItems (items: PortalItem[], permanentDelete?: boolean): Promise<DeleteItemsResult[]>
Since
ArcGIS Maps SDK for JavaScript 4.8

Deletes items from the user's portal content.

See also
Parameters
ParameterTypeDescriptionRequired
items

The portal items to remove.

permanentDelete

= false - Since 4.30. When the recycle bin is enabled and the items to be deleted are item types supported by the recycle bin, this parameter determines if the items should be permanently deleted. If true, the items will be permanently deleted. Otherwise, the items will be moved to the recycle bin. If the recycle bin is disabled, this parameter has no effect. If items are not supported by the recycle bin, they will be permanently deleted regardless of the value of this parameter.

Returns
Promise<DeleteItemsResult[]>

Resolves to an array of DeleteItemsResult.

Example
// Delete items from the user's content.
// This will permanently delete items even if recycle bin is enabled.
let itemArray = [portalItem1, portalItem2, portalItem3];
portal.user.deleteItems(itemArray, true).then((deleteItemsResults) => {
deleteItemsResults.forEach((deleteItemsResult) => {
if (deleteItemsResult.success) {
console.log(`${deleteItemsResult.item.title} deleted from user's content.`);
} else {
console.error(`Error deleting ${deleteItemsResult.item.title}: `, result.error);
}
});
});

fetchFolders

Method
Signature
fetchFolders (): Promise<PortalFolder[]>

Fetches all of the user's folders used to organize portal content.

Returns
Promise<PortalFolder[]>

Resolves to an array of PortalFolder objects representing each of the user's folders in the portal.

Example
// Once portal is loaded, user signed in
portal.load().then(() => {
portalUser.fetchFolders().then((folders) => {
folders.forEach((folder) => {
console.log("User folder", folder.title);
});
});
});

fetchGroups

Method
Signature
fetchGroups (): Promise<PortalGroup[]>

Fetches all the groups that the portal user has permission to access.

Returns
Promise<PortalGroup[]>

Resolves to an array of PortalGroup objects representing each group that the user can access.

Example
// Once portal is loaded, user signed in
portal.load().then(() => {
// fetch all the groups user can access
portal.user.fetchGroups().then((groups) => {
groups.forEach((group) => {
console.log(`${group.title} group`);
});
});
});

fetchItems

Method
Signature
fetchItems (params?: FetchItemsParameters): Promise<FetchItemsResult>

Retrieves all the items in either the user's root folder or the specified folder.

Parameters
ParameterTypeDescriptionRequired
params

See the object specifications table below for the parameters that may be passed as properties in this object.

Returns
Promise<FetchItemsResult>

Resolves to a FetchItemsResult.

Examples
// Retrieves items from the user's root folder.
portal.user.fetchItems().then((fetchItemsResult) => {
console.log("Next start index: ", fetchItemsResult.nextStart);
fetchItemsResult.items.forEach((item) => {
console.log("Portal item title:", item.title);
});
});
// Retrieves items from the recycle bin which will include items from the user's root and subfolders.
portal.user.fetchItems( { inRecyclebin: true, includeSubfolderItems: true }).then((fetchItemsResult) => {
console.log("next start index: ", fetchItemsResult.nextStart);
fetchItemsResult.items.forEach((item) => {
console.log("Portal item title:", item.title);
});
});

fetchTags

Method
Signature
fetchTags (): Promise<Array<{ tag: string; count: number; }>>
Since
ArcGIS Maps SDK for JavaScript 4.14

Fetches the tag objects that have been created by the portal user.

Returns
Promise<Array<{ tag: string; count: number; }>>

Resolves to an array of objects with the following properties:

PropertyTypeDescription
tagstringThe name of the tag.
countnumberThe number of times the tag was used.

getThumbnailUrl

Method
Signature
getThumbnailUrl (width?: number): string | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.4

Get the URL to the thumbnail image for the user.

Available width sizes: 150, 300 and 600.

Parameters
ParameterTypeDescriptionRequired
width

The desired image width.

Returns
string | null | undefined

The URL to the thumbnail image.

queryFavorites

Method
Signature
queryFavorites (queryParams?: PortalQueryParamsProperties): Promise<PortalQueryResult<PortalItem>>

Executes a query against the user's favorite group to return an array of PortalItem objects that match the input query.

Parameters
ParameterTypeDescriptionRequired
queryParams

The input query parameters defined in PortalQueryParams. This object may be autocast.

Returns
Promise<PortalQueryResult<PortalItem>>

When resolved, resolves to an instance of PortalQueryResult which contains a results array of PortalItem objects representing all the items that match the input query.

restoreItem

Method
Signature
restoreItem (item: PortalItem, folder?: PortalFolder | string): Promise<void>
Since
ArcGIS Maps SDK for JavaScript 4.30

Restores an item from the user's recycle bin to their content. This method only applies if the recycle bin is enabled on the organization.

Parameters
ParameterTypeDescriptionRequired
item

The portal item to restore.

folder

The folder to restore the item to. If not specified, the item will be restored to the root folder. If an invalid folder is specified, an error will be returned and the item will not be restored.

Returns
Promise<void>

Resolves when the item has been restored to the user's content.

Examples
// Restore a recycled item to the root folder.
const portalItem = new PortalItem({
id: "affa021c51944b5694132b2d61fe1057"
});
portal.user.restoreItem(portalItem).then(() => {
console.log("Item restored to root folder.")
});
// Restore a recycled item to a specified folder.
const portalItem = new PortalItem({
id: "affa021c51944b5694132b2d61fe1057"
});
// This can be a PortalFolder object or a folder ID string.
const portalFolder = "6bbff8b7f2b54c628603135b72f9cb55";
portal.user.restoreItem(portalItem, portalFolder).then(() => {
console.log("Item restored to folder with ID: '6bbff8b7f2b54c628603135b72f9cb55'.")
});

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
any

The ArcGIS portal JSON representation of an instance of this class.