2

I want to get PublishingPageImagefield value on REST API method on Pages library with below script.

 executor = new SP.RequestExecutor(appwebUrl);
 executor.executeAsync({
    url: appwebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('Pages')/items?@target='" + hostwebUrl + "';
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() },
    success: function (data) {
        // var results = data.d.results;
        var jsonObject = JSON.parse(data.body);
        var results = jsonObject.d.results;


    },
    error: function (data) {
    }
});

I got all the field of collection but seem to miss it out PublishingPageImage field in output.

i have try to get using select method but got error that PublishingPageImage Field is not exist on list.

like this :

 url: appwebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('Pages')/items?@target='" + hostwebUrl + "'&$select=PublishingPageImage;

Anyone try this?

1

It does not seem possible to retrieve Publishing Image fields directly in SharePoint 2013 REST.

But there is a workaround, publishing fields could be retrieved using ListItem.FieldValuesAsHtml property via SharePoint REST endpoint as demonstrated below

Limitation: it requires to perform two requests.

How to retrieve Publishing fields using SharePoint 2013 REST

function getJson(endpointUri, success, error) 
{    
    $.ajax({       
       url: endpointUri,   
       type: "GET",   
       processData: false,  
       contentType: "application/json;odata=verbose",
       headers: {   
          "Accept": "application/json;odata=verbose"
       }, 
       success: success,
       error: error
    });
}


function getPublishingPage(webUrl,listName,listItemId,publishingProperties, success, failure) 
{
    var itemUri =  webUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")";  
    getJson(itemUri,
       function(data){
           var pageItem = data.d;

           var selectProperties = [];  
           for(var idx in publishingProperties){
               if(!pageItem.hasOwnProperty(publishingProperties[idx])){
                   selectProperties.push(publishingProperties[idx]);
               }
           }
           if(selectProperties.length > 0) {
              //construct an additional query 
              var query = '/FieldValuesAsHtml?$select=' + selectProperties.join(',');
              var endpointUri = pageItem['__metadata'].uri + query;
              getJson(endpointUri,
                 function(data){
                    for(var property in data.d){
                       if(property == "__metadata") continue; 
                       pageItem[property] = data.d[property];   
                    }
                    success(pageItem);  
                 },
                 failure);
           } 
           else {
              success(pageItem);
           }   
        },
       failure);
}

Usage

The following example demonstrates how to retrieve page fields including publishing fields, such as PublishingPageImage:

getPublishingPage(_spPageContextInfo.webAbsoluteUrl,'Pages',3,['PublishingRollupImage','PublishingPageImage'],printPageDetails,logError);

function printPageDetails(pageItem)
{
    console.log('Page Publishing Image ' + pageItem.PublishingPageImage);
}

function logError(error){
    console.log(JSON.stringify(error));
}
  • This answer is excellent but by using this we are fetching data of only one item. can we make call and fetch publishing column data of Multiple Items??? – salah9 Jul 3 '18 at 16:14
  • @salah9, it is doable as well, I would suggest to post another question for that matter – Vadim Gremyachev Jul 3 '18 at 16:20

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.