2

I am trying to make a simple query to user's personal site from any site collection on the tenant, however, I am getting error: Unexpected response data from server.

I've tried both with REST and JSOM to open context, but both cases I am receiving this error.

When executing the code against another context / another site collection, I am able to execute queries against it.

What is so special about the personal user's site?

Some example code:

// I've tried context to be either current site collection 
// _spPageContextInfo.webAbsoluteUrl or personal site's URL
$.getScript(SharePoint.Helpers.combineUrls(context, "_layouts/15/SP.RequestExecutor.js"), function () {
            var executor = new SP.RequestExecutor(context);
            executor.executeAsync({
                url: targetUrl, // https://tenant-my.sharepoint.com/personal/user_domain_com/_api/web/lists
                method: "GET",
                headers: {
                    "accept": "application/json;odata=verbose",
                },
                success: typeof (onSuccessFunc) === "function" ? onSuccessFunc : function (data) {
                    window.console && console.log(JSON.parse(data.body));
                },
                error: typeof (onErrorFunc) === "function" ? onErrorFunc : function (err) {
                    alert(JSON.stringify(err));
                }
            });
        });

//JSOM
var clientCtx = new SP.ClientContext(personalSiteUrl);
var web = clientCtx.get_web();
clientCtx.load(web);
clientCtx.executeQueryAsync(function () { alert ("web site url:" + web.get_url()) }, function () { console.log("FAIL")});
Kiril Iliev
  • 103
  • 10

1 Answers1

0

It seems like you are querying another domain, and cross-domain JavaScript calls are blocked for security reasons. You need to pass execCrossDomainRequest as a parameter when getting SP.RequestExecutor.js to execute your query with the JavaScript cross-domain library as described on MSDN:

https://msdn.microsoft.com/en-us/library/office/fp179927.aspx?f=255&MSPPError=-2147217396

Lucas Rodrigues
  • 1,234
  • 2
  • 11
  • 22