1

In a SharePoint Hosted App, with the following code, I can retrieve the list of tasks, every task containing, among others, the identifiers AssignedToId (an array of integers):

executor.executeAsync({
    url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists' +
        '/getByTitle('MyTasks')/items?@target='" + hostweburl + "'",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: successHandler,
    error: errorHandler
});

Instead of the identifier of the users, I want to show the titles of the persons. I can retrieve the title through GetUserById(1) or GetUsers, but this leads to an additional AJAX call I want to avoid.

Is there a way to retrieve this information in a single call?

1 Answer 1

3
_api/Web/Lists/GetByTitle('MyTasks')/Items?$expand=AssignedTo&$select=AssignedTo/FirstName,AssignedTo/LastName

(Tested on 365)

Note that you need to $select all the fields you need when using $expand like this.

1
  • Nice! I thought $expand can be applied to values only, not arrays of values. Commented Apr 1, 2015 at 10:24

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.