Is there a way to get all the lists in the subsites where the list is named 'Posts'? This gets the list if it is deployed on the subsite itself but not from the parent. The hostUrl looks like 'http://contoso/' I need it to look like 'http://contoso/site/blog', the AppPart will be deployed on the parent and I want it reusable so I can publish it to the local SharePoint Store.

var appUrl = GetUrlKeyValue("SPAppWebUrl");
var hostUrl = GetUrlKeyValue("SPHostUrl");

var url = appUrl +
      "_api/SP.AppContextSite(@target)/web/lists/getbyTitle('Posts')/items?" +
      "$select=ID,Title,Body,NumComments,Published&$orderby=Published&" +
      "@target='" + hostUrl + "'";
  • You're going to have to iterate through all the subsites and make multiple calls. It's gonna be ugly, especially if you want it to be recursive. – wjervis Jun 25 '15 at 13:28
  • Can I filter through them with the BLOG#0 template ID? Is that stored somewhere? Can you describe how to go through them? – Christopher Jun 25 '15 at 15:59
  • Do you have any blog sites that are under a site that is not a subsite? If so, and you want it to be recursive, then unfortunately you can't filter them out. If not, then simply adding $filter=WebTemplate eq 'BLOG' to the request should work. – wjervis Jun 25 '15 at 16:25
  • I only care about blogs that are first level sites, under the site in question. – Christopher Jun 25 '15 at 17:17
  • You mind creating an example? I'll mark it as the answer if it works. – Christopher Jun 25 '15 at 19:00

It is definitely a mess but I figured it out. I decided to just use a app property eventually and make the user enter the url, but here's the answer for the above.

 var blogUrl = appUrl + "/_api/site/rootWeb/webinfos?$filter=(WebTemplate%20eq%20'BLOG')";

That will get all the blog sub sites and from within that you can iterate through and get all the blogs' Post lists.

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.