0

When i retrieve data from a person and group column this is what i get as a string below

{"__metadata":{"id":"3d427c6e-2322-4121-b106-f248277eab3f","type":"SP.Data.UserInfoItem"},"LastName":"XXX"}

How can i retrieve XXX ad not the whole metadata string

Currently i'm doing the below

var myAngApp = angular.module('SharePointAngApp', []);  
    myAngApp.controller('spCustomerController', function ($scope, $http) {  
        $http({  
            method: 'GET',  
            //url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Test')/items?$select=Title",  
           url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Test')/items?$select=Title,Notify/LastName&$expand=Notify/id",
            headers: { "Accept": "application/json;odata=verbose" }  
        }).success(function (data, status, headers, config) {  
            $scope.customers = data.d.results;  
        }).error(function (data, status, headers, config) {  

        });  
    });  
3
  • 1
    Do you mean you do not want to use $expand? If so you have to do multiple queries (which expand does for you server-side) Commented Nov 29, 2016 at 8:03
  • Thanks Danny for the response but thats not the case Will modify my question
    – naijacoder
    Commented Dec 1, 2016 at 13:04
  • 1
    You probably want nometadata instead of verbose, but you will still get a JSON object, not just XXXX Commented Dec 1, 2016 at 13:24

1 Answer 1

0

an API result is always some type of Object, hardly ever a string

Note that the SP Search API returns a completely different JSON structure than calling a List endpoint

So you have to proces the result yourself to get a single value.

You can trim down how much you get back with the nometadata , minimalmetadata settings: https://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/

JavaScript to learn:

2
  • Thanks guys for the response. My issue is how can i retrieve a Person or Group field. Using this url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Test')/items?$select=Title,Notify/LastName&$expand=Notify/id", I can receive the title but i can't get to retrieve a name instead i get an object "{"__metadata":{"id":"3d427c6e-2322-4121-b106-f248277eab3f","type":"SP.Data.UserInfoItem"},"LastName":"XXX"}"
    – naijacoder
    Commented Dec 2, 2016 at 1:09
  • Got it. Just needed to add this {{customer.Notify.Title}}
    – naijacoder
    Commented Dec 2, 2016 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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