I am getting some problems with a request I got from a customer and I would like to know if there is someone that can help me :-) 

The case is this: There is a site collection that has several subsites. Each subsite represent a projekt. There will be many subsites so the customer wants the possibility to filter the result by the year when the project was created. I was thinking that a solution can be create a list with one view by year (or when the project was created). The reason for why  I think in using a list is beacause the customer will need to update the date of the proyect and that is easy to do in a list. 

Well the problem is this: I have a hosted app that lists subsites and when they were created. The code looks like this:

        url: appweburl + "/_api/SP.AppContextSite(@target)/web/webs?@target='" + hostweburl + "'",
        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        success: successHandler,
        error: errorHandler

And I consume it like this: 

function successHandler(data) {
    var jsonObject = JSON.parse(data.body);
    var items = [];
    var results = jsonObject.d.results;

    $(results).each(function () {

        items.push('<li class="element">'
            + '<a target="_parent" href="' + this.Url + '">' + this.Title + '</a>'
            + '</li>');

    $("#lisSiteContainer ul").html(items.join(''));


What I would like to know is how can I make a connection to the list in SharePoint  so I can save the results to it? 

I know that I can connect to the list like this: 

                url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Mina%20Document')/items?@target='" + hostweburl + "'",
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: successHandler,
                error: errorHandler

and retrieve the columns that I want to use, but how can I create two connections in the same app, the one that get the subsites and the other that connect to the list and save the data in the corresponding columns? 

Or, is there a better solution? 

Best regards,


  • I don't know the answer to this, but would just make a comment on working with lists in between different 'levels', since you mention using subsites. Two connected lists in the same site collection might behave differently to two lists split between a top level site and a subsite. I mention this, as you may wish to test this to help narrow down what is causing the problem. – Tally Nov 27 '17 at 9:59
  • Thanks Tally, I will get that in consideration. Do you have some link where I can read more about this? – Americo Perez Nov 28 '17 at 10:48

Get the sub sites and then add the data as list items to a custom list.

Add item to list, we need use POST request with REST API to achieve it.



Pass the link field data like this:

var data = {
    '__metadata': { 'type': 'SP.Data.TestListItem' },
                '__metadata': { 'type': 'SP.FieldUrlValue' },
                'Description': 'Bing',
                'Url': 'http://www.bing.com'
    'Title': 'Test'
  • Thanks. I am using POST to save into the list and it is almost working. Now I am trying to link each title in the list to the corresponding subsite and for that I created a new columns of type Hyperlink but it is giving me 400 error. I tested with a single line column but I am getting the link unformated, that's mean that the column is showing the href-tag instead of the name linking to the subsite. I don't know how to format it. This is how I get the link: var name = "<a href='" + item.Url + "'>" + item.Title + "</a>"; and this is how I am sending it to the list: Link: name – Americo Perez Nov 28 '17 at 10:52
  • I update the reply with the code snippet to pass the hyperlink field in REST API – LZ_MSFT Nov 29 '17 at 1:23

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.