2

I have the following JSON response:

{ "d": { "results": [ { "__metadata": { "id": "c55209ae-2af9-4514-ab02-67f222903f6d", "uri": "https://site-GUID.sharepoint.com/sites/dev/MyApp/_api/Web/Lists(guid'46f26a73-0079-4662-ae99-7f4be03e26a4')/Items(1)", "etag": "\"1\"", "type": "SP.Data.LstDoelenListItem" }, "scDoelnaam": "Hoofddoel Afdeling", "scDoellevel": 1 }, { "__metadata": { "id": "7e79ab8a-e550-4694-87d4-26d6f5bc6128", "uri": "https://site-GUID.sharepoint.com/sites/dev/MyApp/_api/Web/Lists(guid'46f26a73-0079-4662-ae99-7f4be03e26a4')/Items(2)", "etag": "\"1\"", "type": "SP.Data.LstDoelenListItem" }, "scDoelnaam": "Subdoel 1", "scDoellevel": 2 }, { "__metadata": { "id": "c204acca-0362-4bd6-a66b-00236a2320cb", "uri": "https://site-GUID.sharepoint.com/sites/dev/MyApp/_api/Web/Lists(guid'46f26a73-0079-4662-ae99-7f4be03e26a4')/Items(3)", "etag": "\"1\"", "type": "SP.Data.LstDoelenListItem" }, "scDoelnaam": "Subdoel 2", "scDoellevel": 2 }, { "__metadata": { "id": "b78b2416-7813-4e64-a920-f9ba377fa36d", "uri": "https://site-GUID.sharepoint.com/sites/dev/MyApp/_api/Web/Lists(guid'46f26a73-0079-4662-ae99-7f4be03e26a4')/Items(4)", "etag": "\"1\"", "type": "SP.Data.LstDoelenListItem" }, "scDoelnaam": "Subdoel 3", "scDoellevel": 2 } ] } 

}

I know how to retrieve the values once I know the column names, but how do I get the 2 column names "scDoelnaam" and "scDoellevel" with Javascript and assign them to variables??

2 Answers 2

2

The following REST endpoint demonstrates how to retrieve List resource with Fields and Items properties:

/_api/web/lists/getbytitle('<list title>')?$expand=items,fields 

Example

var endpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Documents')?$expand=items,fields"; getJson(endpointUrl) .done(function(data) { var fields = data.d.Fields.results; //get fields var items = data.d.Items.results; //get items }) .fail( function(error){ console.log(JSON.stringify(error)); }); 

where

function getJson(url) { return $.ajax({ url: url, type: "GET", contentType: "application/json;odata=verbose", headers: { "Accept": "application/json;odata=verbose" } }); } 
0
0

The query _api/Web/Lists(guid'46f26a73-0079-4662-ae99-7f4be03e26a4')/Fields will give you the fields in the list. From the results you can get both the display name and the internal name of all the fields.

1
  • mm indeed, but isn't there an easier way? Now I have to run a second query to achieve the field names of the first query. Thanks for yr reply :) Commented Feb 12, 2015 at 3:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.