0

This is my code at the moment. With this I get the information of a site. And of the requested site I want to get the parent ID.

I found a query: _api/Web/Lists/getByTitle('TaskListName')/items(3)/ParentID But this is for a list. and I need it for a site.

$.ajax({
    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/webs?$select=ServerRelativeUrl,Title,Id,SiteLogoUrl",
    method: "GET",
    headers: {"Accept": "application/json; odata=verbose"},
    success: function(subsites) {
                        console.log(subsites)
                var aSites = subsites.d.results;

            $.each(subsites.d.results, function(x,index) {
                getSubSites(this.ServerRelativeUrl, this.Title);

            var sID = (aSites[x].Id);
            var sTitle = (aSites[x].Title);
            var siteLogo = (aSites[x].SiteLogoUrl);
            var sURL = (aSites[x].ServerRelativeUrl);
            var sParent = "Moet nog gemaakt worden";
            console.log("Naam site: " + sTitle);
            console.log("ID: " + sID);
            console.log("URL: " + sURL);
            console.log("Parent: " + sParent);
            console.log("-------------------------------------------")
            var newDIV = jQuery('<tr> <td>' + sTitle + '</td> <td>' + sURL + '</td> <td>' + sID + '</td> <td>' + sParent + '</td> <td><img src="' + siteLogo + '" height="50px" width="50px"></img> ' + siteLogo + '</td></tr>');
                   newDIV.find("table" ).val(newDIV);
                   $('table').append(newDIV);
            }); 
    },
    error: function(subsites) {},
    async: false
});
  • Hi do you want the Id of the Site – Sunil Sahu Feb 28 '17 at 10:59
  • How do you mean how I want the ID? I want the GUID from the parent site as a string – TheMrkt Feb 28 '17 at 11:07
1

You can use the below endpoint to get the Id of the parent web:

 _spPageContextInfo.webAbsoluteUrl/_api/web/parentweb?$select=Id

Check below screenshot to check the JSON response:

enter image description here

0

As you mentioned that you want the parent site Guid so you can use below rest end point to get Guid:-

//Guid for Site Collection

 `url: _spPageContextInfo.siteAbsoluteUrl + "/_api/Site?$select=Id"'

//Guid and Title Parent Web

`url: _spPageContextInfo.siteAbsoluteUrl + "/_api/Web/ParentWeb?$select=Id,Title"'
  • If you have site: http:// site.com/sitecol/site1/site2 I want to get the GUID of site 1 when I use the API to get information from site 2 – TheMrkt Feb 28 '17 at 11: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.