There are five Custom Lists in a site collection, all have same content type. I would like to get all items from those five lists using rest api. Is there a way to get all items from all lists having a specific content type using rest api?
1 Answer
Yes, you can query search using the REST API with the following URL to get list items specific to a content type:
http://yoursite.domain.com/_api/search/query?querytext='contenttype:CONTENT_TYPE_NAME'
To find out more about search using REST see this and this links.
-
1To add to this, it may be easier to create a result source, and simply use the sourceid parameter:
https://<site>/_api/search/query?sourceid='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
. This will allow you to test your query before messing with code.– wjervisSep 22, 2014 at 11:33 -
1I sued your solution in the browser but I got
this web page can not be displayed
– MedesSep 22, 2014 at 12:15 -
Do you have crawled content in your search index ? You can check it by querying into the default seach box in the site to make sure that search is returning the results. You can try to change the browser settings to see if the REST query used in browser returns the results. Check this. Also, to test the rest query for content type try querying 'contenttype=ITEM' to see if the search works. Sep 22, 2014 at 12:25
-
Sorry about my mistake, I tested it on my Online dev environment and it works, it seems my VM have some problem regarding crawling and search becasue search not works at all. I get no result when I search– MedesSep 22, 2014 at 12:37
-
1