5

I'm looking for some help with a REST call I'm attempting to make in SharePoint Online.

I'm doing an add-in that gives me the name, birhday and photo property of all user in user profiles

enter image description here

I tried with this code

 var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
    Console.log(siteUrl);
    $.ajax({
        url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            console.log(data);
        },
        error: function(error) {
            console.log(error);
        }
    });

but I only get current user profile properties, what I need is all user profiles properties for all users, how can i achieve that?

Thanks in advance!

Emmanuel Villegas
  • 497
  • 4
  • 7
  • 25
  • all users of the site or on the tenant level? here is a link to a similar question http://sharepoint.stackexchange.com/questions/148313/how-to-get-all-properties-of-all-users-in-sharepoint-2013-rest-api – Ahmed Mahmoud May 25 '16 at 16:29
  • Is below given solutions works for you? – Hardik May 26 '16 at 12:31

4 Answers4

12

Still this no API for retrieving all user profiles from SharePoint Online

You can get current user's profile

_api/SP.UserProfiles.PeopleManager/GetMyProperties

Or a particular user's profile by login name

/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|xx@siteurl.onmicrosoft.com'

BUT You can get available user profiles in a site

/_vti_bin/ListData.svc/UserInformationList
Hardik
  • 7,733
  • 2
  • 18
  • 37
  • How about SP.UserProfiles.js? Yes I know OP specifically say REST, but this should actually work, also for apps (which is not so easy with _vti_bin). – eirikb May 25 '16 at 18:00
  • You can get the user information from UserInformationList using SP.UserProfiles.js. But if you want to get users using the tanent than there is no option. – Hardik May 25 '16 at 18:02
  • thanks for the replays, with /_vti_bin/ListData.svc/UserInformationList i get Failed to load resource: the server responded with a status of 404 (Not Found) i used it like that, var url = _spPageContextInfo.siteAbsoluteUrl + "/_vti_bin/ListData.svc/UserInformationList";

    is it wrong?

    – Emmanuel Villegas May 25 '16 at 19:29
  • 1
    It is used to get the user's information from SharePoint's default (hidden) list called UserInforamtion. – Hardik May 25 '16 at 19:30
  • 1
    I gave this as another option but you need users from tanent & it is not possible to get all user's all information from tanent using REST. :) – Hardik May 25 '16 at 19:31
  • okay, thanks man, so, what do you recommend to me to do to achieve it? get all user's all information from users profile, using other method or strategy. – Emmanuel Villegas May 25 '16 at 19:37
  • If that is the case than you can get your answer from here...http://sharepoint.stackexchange.com/questions/123166/rest-api-and-user-information-list-permissions-and-breeze-js – Hardik May 25 '16 at 19:41
  • You can refer this as well...http://sharepoint.stackexchange.com/questions/154566/call-entire-user-information-list-from-rest-api – Hardik May 25 '16 at 19:41
  • So, there is and option to get the user profiles from the tenant? CSOM, JSOM? – Sebastián A May 25 '16 at 20:12
  • 1
    Unfortunately there is no option for SharePoint Online. – Hardik May 25 '16 at 20:13
  • Is given solutions works for you? @Emmanuel Villegas – Hardik May 25 '16 at 20:13
  • 1
    @Hardik We have the birthday but when I get the User Information List fron this link http://SiteURL/_vti_bin/listdata.svc/UserInformationList the Birthday is null <d:DateOfBirth m:type="Edm.DateTime" m:null="true" /> – Sebastián A May 25 '16 at 22:11
  • Does this work for external or guess users in SharePoint Online? – Joshua Dominic Sibug Mar 05 '19 at 11:38
2

you can use SPFx People Picker (version 11+) which was released recently at https://sharepoint.github.io/sp-dev-fx-controls-react/controls/PeoplePicker/ .

Basically, this control will allow you to pick any users in all trusted domains in SharePoint Online.

1

URL:

http://SiteURL/_api/Web/lists/getbytitle('User Information List')/Items

Headers:

Accept: application/json; odata=verbose
Content-Type: application/json; odata=verbose
0

install pnpjs (https://pnp.github.io/pnpjs/)

npm i @pnp/pnpjs

import { sp } from "@pnp/pnpjs";
    import { SearchQueryInit } from "@pnp/sp/search";
    public async getSearchResults(startRow, rowLimit): Promise&lt;[]&gt; {
            let allResults: any = [];
            let queryParams: any = this._getQueryParams(
                startRow,
                rowLimit
            );
            queryParams.Timeout = 60000;
            const results = await (sp as any).search(queryParams);
            allResults.data = results.PrimarySearchResults;
            allResults.totalRows = results.TotalRows;
            return allResults;
        }
        private _getQueryParams(
            startRow: number,
            rowLimit: number
        ) {
            let queryParams: SearchQueryInit = {
                RowLimit: rowLimit,
                Querytext: &quot;*&quot;,
                SelectProperties: [&quot;AccountName&quot;],
                StartRow: startRow,
                SourceId: &quot;b09a7990-05ea-4af9-81ef-edfab16c4e31&quot;,
                TrimDuplicates: false,
            };
            return queryParams;
        }
     this.getSearchResults(0, 50)