0

enter image description here

enter image description here

Site contents images are attached to this question page.

I need to crawl the metadata for the pages/atozindex.

It contains the a to z documents. How to form the request by using restAPI? Can anyone assist on this?

https://www.sitecontent.com/_api/web/Lists/GetByTitle('Pages')/items?$select=ID,Title,FileRef

marked as duplicate by Ganesh Sanap, MHeld, Community Mar 15 at 10:29

This question was marked as an exact duplicate of an existing question.

0

The problem is that in your URL, you specify the title of the list as 'Pages'. It should be 'Site Pages'. It generally shows up on the Quick Launch nav as 'Pages', but that's not actually the title of the list. Other than that, your end point URL is correct, so this works:

$.ajax({
    // same REST end point, but changed the list title
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/Lists/GetByTitle('Site Pages')/items?$select=ID,Title,FileRef",
    async: false,
    headers: {
        'accept': 'application/json;odata=nometadata'
    },
    complete: function(request) {
        console.log("Request: " + JSON.stringify(request, null, 4));
    }, 
    error: function(request) {
        console.log(JSON.stringify(request, null, 4));
    }
});

The response looks like this:

Request: {
    "readyState": 4,
    "responseText": "{\"value\":[{\"Id\":4,\"Title\":null,\"ID\":4,\"FileRef\":\"/sites/csrdemos/SitePages/Sub\"},{\"Id\":1,\"Title\":null,\"ID\":1,\"FileRef\":\"/sites/csrdemos/SitePages/Home.aspx\"},{\"Id\":2,\"Title\":null,\"ID\":2,\"FileRef\":\"/sites/csrdemos/SitePages/How To Use This Library.aspx\"},{\"Id\":3,\"Title\":null,\"ID\":3,\"FileRef\":\"/sites/csrdemos/SitePages/slider.aspx\"},{\"Id\":5,\"Title\":null,\"ID\":5,\"FileRef\":\"/sites/csrdemos/SitePages/Sub/Tester.aspx\"}]}",
    "responseJSON": {
        "value": [
            {
                "Id": 4,
                "Title": null,
                "ID": 4,
                "FileRef": "/sites/csrdemos/SitePages/Sub"
            },
            {
                "Id": 1,
                "Title": null,
                "ID": 1,
                "FileRef": "/sites/csrdemos/SitePages/Home.aspx"
            },
            {
                "Id": 2,
                "Title": null,
                "ID": 2,
                "FileRef": "/sites/csrdemos/SitePages/How To Use This Library.aspx"
            },
            {
                "Id": 3,
                "Title": null,
                "ID": 3,
                "FileRef": "/sites/csrdemos/SitePages/slider.aspx"
            },
            {
                "Id": 5,
                "Title": null,
                "ID": 5,
                "FileRef": "/sites/csrdemos/SitePages/Sub/Tester.aspx"
            }
        ]
    },
    "status": 200,
    "statusText": "OK"
}

As you can see, this returns the meta data for all pages in the 'Site Pages' library, even if they are in sub-folders. To get additional fields back, just add them to the $select= query parameter. It is a comma separated list of field internal names.

I tested this in the browser console on a SharePoint online site where jQuery is loaded into each page. If you don't have jQuery loaded on your site, you can test it by first running this in the console:

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.js';
document.head.appendChild(script);

This will load jQuery. If you refresh the page, you'll need to load jQuery again. Then you can copy and paste the above code as is, and it will console.log the returned results.

  • I tried to as your query in POSTMAN but i'm getting the below error. Still getting the confusion for formation of Request sitecontent.com/_api/web/Lists/GetByTitle('Pages/…: false, sitecontent.com/_api/web/Lists/…: false, "value": "The expression \"ID,Title,FileRef,async: false,\" is not valid." – Anandhan Mar 14 at 13:52
  • I am using POSTMan Request with Java. Could u please assist on the same. I tried site pages but even though the same error. – Anandhan Mar 14 at 14:01
  • The URL in your comment, doesn't look like my URL. First, you're trying to run GetByTitle('Pages/atozindex.aspx'), which isn't even close to GetByTitle('Site Pages') in my answer. You also added ,async to the end of your query, so now SharePoint is looking for a field named async, which is not valid. I did end up with some extra spaces in my URL, so I've edited my answer to remove them and also provided some additional information about how I tested my code in the browser debug tools. I don't have Postman, so I can't advise you on testing with that tool. – Joe McShea Mar 14 at 14:04
  • Just to make sure we're on the same page, the title is case sensitive, so 'site pages' will not work, it needs to be 'Site Pages'. – Joe McShea Mar 14 at 14:06
  • site pages will not work, needs to be Site Pages, and remove ,async from the end of your query. – Joe McShea Mar 14 at 14:10

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