0

I'm trying to figure out if what I'm looking to do is possible. We have existing websites that are not Sharepoint based. Internally, we have an anonymous enabled Sharepoint site we'd like to publish documents to and then from the external websites, use CSOM to call into it to pull the documents back and then display them on each website. I'm using the cross domain calls as described by MSDN:

var hostweburl;
  var appweburl;

  // Load the required SharePoint libraries
  $(document).ready(function () {
    //Get the URI decoded URLs.
    hostweburl =
        decodeURIComponent(
            "https://public.mysite.com"
    );
    appweburl =
        decodeURIComponent(
            "https://public.mysite.com"
    );

    // resources are in URLs in the form:
    // web_url/_layouts/15/resource
    var scriptbase = hostweburl + "/_layouts/15/";

    // Load the js files and continue to the successHandler
    $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
  });

  // Function to prepare and issue the request to get
  //  SharePoint data
  function execCrossDomainRequest() {
    // executor: The RequestExecutor object
    // Initialize the RequestExecutor with the app web URL.
    var executor = new SP.RequestExecutor(appweburl);

    // Issue the call against the app web.
    // To get the title using REST we can hit the endpoint:
    //      appweburl/_api/web/lists/getbytitle('listname')/items
    // The response formats the data in the JSON format.
    // The functions successHandler and errorHandler attend the
    //      sucess and error events respectively.
    executor.executeAsync(
        {
          url:
              appweburl +
              "/_api/web/lists/getbytitle('Documents')/items",
          method: "GET",
          headers: { "Accept": "application/json; odata=verbose" },
          success: successHandler,
          error: errorHandler
        }
    );
  }

If I pull up the site in an external browser, I can navigate to it anonymously. But when I try to call it from other websites, I get the error message:

Could not complete cross-domain call: App Web is not deployed for this app's request url https://public.mysite.com

This is not a Sharepoint hosted application. It just a plain, external website trying to anonymously call into an anonymous enabled web application for its documents. Has anyone been able to accomplish this?

0

You are trying to use Cross-domain library for SharePoint Apps model, that is part of SharePoint, it is not available outside of SharePoint.
SP.RequestExecutor.js gives you the opportunity to simplify JavaScript scenarios specifically in SharePoint App by removing the need to work with OAuth tokens.

If you need to access SharePoint data from another site you should use raw REST web services calls, for example, using jQuery. But also keep in mind that you should take care of autentificaton to SharePoint.

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.