SpRestLib

SpRestLib

  • Download
  • Get Started
  • API Documentation
  • SharePoint Guides
  • GitHub

›API Reference

Get Started

  • Installation
  • Promise You Will Love It
  • Promise-based Operations

Features

  • Library Integration
  • Library Options
  • SharePoint via Node.js
  • Utility Methods

API Reference

  • List/Library Methods (SP.List)
  • File Methods (SP.File)
  • Folder Methods (SP.Folder)
  • Site Methods (SP.Web)
  • User Methods (SP.User)
  • REST API Methods

SpRestLib UI

  • Form Binding

Help / Support

  • SharePoint Authentication

User Methods (SP.User)

Syntax

sprLib.user()
sprLib.user(options)

Usage: Omitting options will return information about the current user, otherwise, the specified user is returned.

User Query Properties

PropTypeRequired?DescriptionPossible Values
baseUrlstringthe base urlEx:{'baseUrl': '/sites/dev'}
idnumberuser iduser id to query. Ex: {id:99}
emailstringuser email addressuser email to query. Ex: {email:'brent@github.com'}
loginstringuser login nameuser loginName to query. Ex: {login:'AMERICAS\Brent_Ely'}
titlestringuser titleuser title to query. Ex: {title:'Brent Ely'}

Get User Information (SP.User)

Syntax:
sprLib.user().info()
sprLib.user(options).info()

Returns: Object with SharePoint user (SP.User) properties.

Note: Uses the basic SP User service (not the Enterprise licensed User Profile service)

Sample Code

// EXAMPLE: Get current user info
sprLib.user().info()
.then(function(objUser){ console.table([objUser]) });

// EXAMPLE: Get user info by email address
sprLib.user({ email:'brent@microsoft.com' }).info()
.then(function(objUser){ console.table([objUser]); });

// RESULT:
/*
.--------------------------------------------------------------------------------------------.
| Id |              LoginName                |   Title   |        Email        | IsSiteAdmin |
|----|---------------------------------------|-----------|---------------------|-------------|
|  9 | i:0#.f|membership|brent@microsoft.com | Brent Ely | brent@microsoft.com | true        |
'--------------------------------------------------------------------------------------------'
*/

Get User Groups (SP.Group)

Syntax:
sprLib.user().groups()
sprLib.user(options).groups()

Returns: Array of objects containing the user's SharePoint groups SPGroup

Sample Code

sprLib.user().groups()
.then(function(arrGroups){ console.table(arrGroups) });

// RESULT:
/*
.-----------------------------------------------------------------------------------------.
| Id |      Title       |        Description         |   OwnerTitle    |    LoginName     |
|----|------------------|----------------------------|-----------------|------------------|
|  6 | Dev Site Owners  | Use for full control perms | Dev Site Owners | Dev Site Owners  |
|  7 | Dev Site Members | Use for contribute perms   | Dev Site Owners | Dev Site Members |
'-----------------------------------------------------------------------------------------'
*/

Get User Profile Properties (SP.UserProfile)

Syntax:
sprLib.user().profile()
sprLib.user(options).profile()
sprLib.user(options).profile('DirectReports')
sprLib.user(options).profile(['DirectReports', 'Email'])

Usage: Current user is selected unless options is provided.

Returns: Object with SP.UserProfile.PersonProperties

Notes:

  • The User Profile Service API is only available for enterprise licensed on-prem or Office online.
  • Omit profile arguments to query all properties, or specify 1 or more as an array of property names

Person Properties

Property NameTypeDescription
AccountNamestringaccount name
DirectReportsarrayarray of user's direct reports
DisplayNamenumberdisplay name
Emailobjectemail address
ExtendedManagersstringExtended Managers
ExtendedReportsstringExtended Reports
IsFollowedstringIs Followed
LatestPoststringLatest Post
Peersstringarray of peer users
PersonalSiteHostUrlstringPersonalSiteHostUrl
PersonalUrlstringpersonal website url
PictureUrlstringprofile picture url
Titlestringtitle
UserProfilePropertiesobject100+ properties: Manager, PhoneticFirstName, WorkPhone, etc.
UserUrlstringPerson.aspx profile page url

Sample Code

// EXAMPLE: Current User: Get all Profile properties
sprLib.user().profile()
.then(function(objProps){ console.table([objProps]) });

// RESULT:
/*

.-------------------------------------------------------------------------------------.
|       Prop Name       |                         Prop Value                          |
|-----------------------|-------------------------------------------------------------|
| AccountName           | i:0#.f|membership|brent@contoso.onmicrosoft.com             |
| DirectReports         | []                                                          |
| DisplayName           | Brent Ely                                                   |
| Email                 | brent@contoso.onmicrosoft.com                               |
| ExtendedManagers      | []                                                          |
| ExtendedReports       | ["i:0#.f|membership|brent@contoso.onmicrosoft.com"]         |
| IsFollowed            | null                                                        |
| LatestPost            | null                                                        |
| Peers                 | []                                                          |
| PersonalSiteHostUrl   | https://sharepoint.com:443/                                 |
| PersonalUrl           | https://sharepoint.com/personal/brent_onmicrosoft_com/      |
| PictureUrl            | https://sharepoint.com:443/Profile/MThumb.jpg?t=63635514080 |
| Title                 | null                                                        |
| UserProfileProperties | {"UserProfile_GUID":"712d9300-5d61-456b-12d3-399d29e5e0bc"} |
| UserUrl               | https://sharepoint.com:443/Person.aspx?accountname=         |
'-------------------------------------------------------------------------------------'
*/

// EXAMPLE: Specified User: Single Profile property
sprLib.user({ email:'brent@microsoft.com' }).profile('ExtendedReports')
.then(function(objProps){ console.table([objProps]) });

// RESULT:
/*
.-------------------------------------------------------------------------------------.
|       Prop Name       |                         Prop Value                          |
|-----------------------|-------------------------------------------------------------|
| ExtendedReports       | ["i:0#.f|membership|brent@contoso.onmicrosoft.com"]         |
'-------------------------------------------------------------------------------------'
*/
← Site Methods (SP.Web)REST API Methods →
  • Syntax
  • User Query Properties
  • Get User Information (SP.User)
    • Sample Code
  • Get User Groups (SP.Group)
    • Sample Code
  • Get User Profile Properties (SP.UserProfile)
    • Person Properties
    • Sample Code
SpRestLib
Docs
Getting Started with SpRestLibSharePoint API ReferenceSharePoint Development GuidesAbout JavaScript Promises
Community
FacebookTwitterPinterestYouTube Channel
More
GitHub IssuesGitHub ProjectSpRestLib on Stack OverflowSite Icons
Copyright © 2019 Brent Ely