3

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

2 Answers 2

6

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: []
    });
});
2

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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