Question

I'm trying to write a sharepoint 2013 add-in that reads certain list info from a bunch of site collections i get first and write into an array, however whenever i try to access any sitecollection but the current one the add-in is deployed at, all i get is a login screen with "your connection to this site is not private" and any sharepoint credentials not working, canceling that gives me

app url/_api/SP.AppContextSite(@target)/web/lists@target=%27*site collection url*%27 401 (Unauthorized)

The code i'm currently using is

searchDocumentLibrary2(pathURL, parent) {       

let that = this;
    return new Promise(function (resolve, reject) {
        $.getScript(pathURL + "/_layouts/15/SP.RequestExecutor.js").done(function (script, textStatus) {

            var executor = new SP.RequestExecutor(that.appWebUrl);

            executor.executeAsync(
                {

                    url: that.appWebUrl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + pathURL + "'",
                    method: "GET",
                    headers: { "Accept": "application/json; odata=verbose" },
                    success: function (data) {
                      > bunch of stuff

                        resolve(>bunch of stuff);
                    },
                    error: function (data) {
                        >bunch of other stuff
                        reject(>bunch of other stuff);
                    }

              });
       });
    });
}

The Add-in does have Tenant permissions.

Was it helpful?

Solution

For cross site collection scripts to work in app you have to do below things:

  1. Tenant level permissions
  2. Tenant scope deployment of the app.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top