Firstly I'll start with extra question:

I'm trying to get data by _api/web/getuserbyid() API call in code. Do You guys know why there is no option for filtering by query for specific data? I mean by:


But know going to the subject of .map (the code is shown below) I've got error:

Uncaught (in promise) TypeError: Cannot read property 'map' of undefined


export interface ISponsorData{
  Title: string;
  UserPrincipalName: string;


private _sponsorData: ISponsorData[] = [];


private _getSponsorDetails(): Promise<any[]>{
    var _sponsorURL = `https://my.sharepoint.com/sites/SC/_api/web/getuserbyid(6)`;

    return this.context.spHttpClient.get(_sponsorURL,SPHttpClient.configurations.v1)
    .then((response: SPHttpClientResponse): Promise<{value: ISponsorData[]}> => {
      return response.json();
    .then((json: {value: ISponsorData[]}) => {
        return this._sponsorData=json.value.map((k,i) =>({
          Title: k.Title,
          UserPrincipalName: k.UserPrincipalName

for now log below is set as undefined (no suprise here)


When I'm printing to the console console.log(response.json());, I've proper response from the API call:

[PromiseValue]]: Object
@odata.context: "https://MY.sharepoint.com/sites/SC/_api/$metadata#Users/$entity"
@odata.editLink: "Web/GetUserById(6)"
@odata.id: "https://MY.sharepoint.com/sites/SC/_api/Web/GetUserById(6)"
@odata.type: "#SP.User"
Email: "[email protected]"
Expiration: ""
Id: 6
IsEmailAuthenticationGuestUser: false
IsHiddenInUI: false
IsShareByEmailGuestUser: false
IsSiteAdmin: true
LoginName: "i:0#.f|membership|n[email protected]"
PrincipalType: 1
Title: "Name LastName"

I've found on stackoverflow, that the error might be caused if values were null, but they are not. What possible is wrong with my approach? I've used =json.value.map((v,i) =>({ before and it is working, and it was also for spHttpClient Call.

1 Answer 1


GetUserById does not return a collection (array), map is for iterating. GetUserById returns just a object.

You access the properties with; json.value.Title

For using $select you can do: https://my.sharepoint.com/sites/SC/_api/web/getuserbyid(6)?$select=Title,UserPrincipalName

  • Thanks a lot @AndersAune
    – KKania
    May 8, 2019 at 13:26

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.