Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I get the ContentType Field value From Task List Using REST API In SharePoint 2013 ?

I tried this code and i got results for ID, Title etc. but for the ContentType field he returned "deferred"

$(document).ready(function() {

jQuery.ajax({
   url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Tasks')/items",
   type: "GET",
   dataType: 'json',
   headers: { "Accept": "application/json;odata=verbose" },
   success: function(data, textStatus, xhr) {
  var dataResults = data.d.results;
 alert(JSON.stringify(dataResults));
            },
    error: function(xhr, textStatus, errorThrown) {
    alert("error:"+JSON.stringify(xhr));
    }
});

 });
share|improve this question

2 Answers 2

up vote 1 down vote accepted

The task object that is being returned contains "links" to other objects, link the content type. Instead of serializing and returning all objects connected to the requested task, it returns the key field (ContentTypeId), and a "deferred" item that contains the URI to the associated item. So, you could grab that URI and make another request to get whatever info you want about the ContentType. Or, try the following:

_api/web/lists/getbytitle('Tasks')/items?$expand=ContentType

The above tells it to go ahead and serialize the ContentType object along with the items.

share|improve this answer
    
Thanks, using $expand=ContentType, worked. –  Alex Choroshin Apr 25 '13 at 6:08

Take a look at the REST API page, for more information. It sounds as the contet type that is is giving you is the request content type and not the actual item content type. Try adding a ?$select field1,field2,ContentType,field3 to the URL.

share|improve this answer
    
Thanks but I already tried it and the result is still "deferred" –  Alex Choroshin Apr 25 '13 at 6:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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