3

I have simple SharePoint custom list. It has 3 columns,

1) Title

2) Manager (Person or group type)

3) Type (Managed metadata - single value).

Now i tried to get the value of the list items. However, i am not able to get the values in a single REST API call.

If I use the standard _api/web/lists/GetByTitle('Test')/items(1) and use $expand, i get the person name but taxonomy guid.

https://sitecollectionurl/_api/web/lists/GetByTitle('Test')/items(1)?expand=Manager&$select=Title,Manager/Title,Type

If I use the CAML query with REST API as below, then i get the taxonomy column label but i get the user's id value and not title.

var caml =  "<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>1</Value></Eq></Where></Query></View>";

var requestData = { "query" :
           {
              "__metadata": 
              { "type": "SP.CamlQuery" }
              , "ViewXml": caml
           }
        };

$http({
            method: "POST",
            url: "https://sitecollectinonurl/_api/web/lists/GetByTitle('Test')/GetItems",
            data: requestData,
            headers: { "Accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose" , "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value }
          });

Is there any way, I can get both the person column and taxonomy column in a single REST API call ?

3

You should be able to do something like this:

url: _spPageContextInfo.siteServerRelativeUrl +
  "/_api/web/lists/getbytitle('listName')/items?" +
  "$select=Author/ID,Author/Title,Author/EMail," +
  "TaxonomyColumn,"
  "TaxCatchAll/ID,TaxCatchAll/Term," +
  "&$expand=Author,TaxCatchAll"

You'll get objects back for Author, TaxonomyColumn, and TaxCatchAll. TaxonomyColumn will have the Term Set object information and TaxCatchAll will have the TaxonomyColumn term.

I am using these headers in my testing, but verbose ought to also work. (I don't want any metadata.)

          headers: {
              "Accept": "application/json; odata=nometadata"
          }

See this post for more info.

  • Thank you so much for the answer. This works at site collection level but not at subsites unfortunately. I have make 2 rest calls :( – Gautam Sheth May 17 '17 at 16:08
  • I'm not sure what you mean. As long as you're going against a single list, it ought to work, whether the list in the the current site or some other site. Note that you are calling a different endpoint than I am: /GetItems vs. /items. – Marc D Anderson May 17 '17 at 16:12
  • If i use the query at https://sitecollectionurl, it works. But the same query if i use at https://sitecollectionurl/subsite , it gives The field 'TaxCatchAll' is not supported in query. The lookup list is in another web. error. I am using the query you posted here - getbytitle('listName')/items – Gautam Sheth May 17 '17 at 16:22
  • FYI - i have two similar lists with same columns(internal names and everything) . One is at the site collection and other is at the subsite. This query works correctly at the site collection but not at subsite. – Gautam Sheth May 17 '17 at 16:34
  • 2
    Ah, ok. You're running into this problem: sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/… The TaxCatchAll column is a hidden "lookup column" in the root site of the Site Collection. – Marc D Anderson May 17 '17 at 16:43

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.