Accessing Additional User Profile Properties From Sharepoint Rest Apis

Overview of User Profiles in SharePoint

User profiles in SharePoint store information about users such as their name, contact information, department, manager, and other attributes. This enables personalized experiences, audiences, permissions, and more. User profiles have a default structure but can be extended with custom properties.

User profile structure

The default user profile contains properties like AccountName, FirstName, LastName, Email, JobTitle, and Department. These correspond to attributes synchronized from directory services like Active Directory or Azure AD if configured. Profiles also contain system-generated properties like UserProfile_GUID for the unique identifier.

Default and custom properties

In addition to the default properties, custom attributes can be created to store information not included out-of-the-box. Common examples include EmployeeID, StartDate, OfficeLocation, and Skills. Custom properties must follow certain syntax rules when created but are otherwise accessed similarly to default attributes.

Profile synchronization

User profile synchronization imports profile data from other systems into SharePoint. This allows centralizing user information from multiple sources. Synchronization requires configuring connections to data sources like Active Directory and mapping attributes between the external system and SharePoint user profiles.

Retrieving User Profile Properties via REST API

SharePoint provides REST APIs to access user profiles and their properties from client applications. Understanding the endpoints, authentication, and permissions is key to retrieving profile data.

Understanding the REST API endpoints

The main endpoint for user profiles is:

/_api/sp.userprofiles.peoplemanager

This retrieves profile data for the current user or others specified in the request. Other endpoints exist as well for user profile updates, editing privacy settings, followers, and more.

Authentication and permissions

Accessing profiles via REST requires proper authentication usually via OAuth or service account. Permissions also need granted to the API consumer application – profiles have a separate permission set from standard SharePoint objects. Read access enables getting profile properties, while write access allows updates.

Example request to get user profile

A simple REST query to retrieve the current user’s profile data looks like:

GET https://tenant.sharepoint.com/_api/sp.userprofiles.peoplemanager/GetMyProperties

The response JSON contains default and custom attributes for the user across the various sections of the profile.

Accessing Additional and Custom Properties

While default profile properties cover many common use cases, often more attributes are needed. Custom properties enable capturing additional data, with some special handling compared to built-ins.

Limitations of default profile properties

Default user profile properties have properties controlled by the system and restrictions on updates in many cases. They also don’t cover all data an organization may store on users and employees. Fields like EmployeeID, Training Completion Status, and Equipment Issued require custom properties.

Mapping custom properties

Creating custom attributes requires specifying parameters like the name, type, length, and section where they will exist in the user profile. These then map to the internal property names like User_Custom_EmployeeID. They can be queried just like other attributes.

Example request to retrieve custom properties

Retrieving custom properties uses the same endpoint but simply includes those names. For example:


GET https://tenant.sharepoint.com/_api/sp.userprofiles.peoplemanager/GetPropertiesFor(accountName=@v)?$select=EmployeeID,OfficeLocation

This returns the custom EmployeeID and OfficeLocation values for the specified user.

Importing Profile Data from External Systems

While profiles can be managed manually, the real power comes from synchronizing properties from other data sources like AD, HR databases, or external systems.

Synchronization process

The synchronization process connects to the data source, matches users between it and SharePoint based on identifiers, and imports profile attributes. The import runs on a schedule but can also be triggered manually. Incremental imports only update changed data.

Mapping external attributes

When configuring synchronization, administrators map fields from the external system to SharePoint profile properties. Commonly imported attributes include name, contact info, department, manager, employee ID, and more. Careful planning of the attribute mapping is important.

Troubleshooting import issues

Sometimes errors occur during synchronization around connectivity, credentials, missing data, duplicates, and more. Monitoring the synchronization logs provides insight into failed imports. Validation rules can also help enforce data quality standards when pulling attributes into profiles.

Best Practices for Managing User Profiles

Properly administering user profiles and custom properties enables organizations to build robust solutions leveraging the user data.

Planning additional properties

Determine what attributes are needed during requirements gathering, how they will be used in solutions later, and the corresponding data types and lengths. Document property definitions and import/export details.

Optimizing performance

Limit custom properties where possible and avoid excessive length strings. Test synchronization times and tune as needed. Create indexes on frequently queried columns. Also leverage caching and batching when querying APIs.

Maintaining data accuracy

Data quality is key to prevent issues reporting on and using user profiles. Have error handling in imports, validation on fields, and periodic auditing. Also check for unused properties to clean up.

Leave a Reply

Your email address will not be published. Required fields are marked *