3

How to get current user profile details using plain Typescript in SharePoint framework. I am not using JSOM or csom.

4

I am using react framework for my SPFx web part and the following example uses the same. But the syntax to call the User Profile REST API is same.

this.props.spHttpClient.get(`${this.props.siteUrl}/_api/sp.userprofiles.peoplemanager/GetMyProperties`,SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse): Promise<{ value: IUser[] }> => {
    return response.json();
}).then((response: { value: IUser[] }): void => {
    alert(response.value);
    this.setState({
        status: '',
        items: response.value
    });
}, (error: any): void => {
    this.setState({
        status: "Failed to load profile...",
        items: []
    });
});
1

I've been using pnp core for this. Its less code

pnp.sp.profiles.myProperties.get()

  .then(userprops => {

    // get your props
}
});

https://gallery.technet.microsoft.com/office/Retrieve-User-Profile-926406f5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.