0

Why can't I call REST of the apps parent site from NAPA? I need data from a list on the same level as the app.

This chokes. And if I use the Apps URL, it can't find the list with GetByTitle.

function ProcessUpload(fileInput) {
var reader = new FileReader();
reader.onload = function (result) {
    var fileName = '',
     libraryName = '',
     fileData = '';

    var byteArray = new Uint8Array(result.target.result)
    for (var i = 0; i < byteArray.byteLength; i++) {
        fileData += String.fromCharCode(byteArray[i])
    }

    // once we have the file perform the actual upload
    PerformUpload(fileInput.name, fileData);

};
reader.readAsArrayBuffer(fileInput);}function PerformUpload(fileName, fileData) {
var url;

var path = appWebUrl; var p = path.split('/');var approot = p[0]+"//"+p[2]+"/"+p[3]+"/"+p[4];


    url = approot +
    "/_api/web/lists/getByTitle(@TargetLibrary)/RootFolder/Files/add(url=@TargetFileName,overwrite='false')?"+
      "@TargetSite='" + targetSiteUrl + "'" +
        "&@TargetLibrary='Documents'" +
        "&@TargetFileName='CV" + fileName + "'";
        alert(url);


// use the request executor (cross domain library) to perform the upload
var reqExecutor = new SP.RequestExecutor(appWebUrl);
alert(appWebUrl);
reqExecutor.executeAsync({
    url: url,
    method: "POST",
    headers: {
        "Accept": "application/json; odata=verbose",
        "X-RequestDigest": digest
    },
    data: JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'Title': 'New title' }),


    contentType: "application/json;odata=verbose",
    binaryStringRequestBody: true,
    body: fileData,
    success:successHandler,
    error: errorHandler
});

}

Might I be having a cross domain issue. Regardless I wonder I can consume list data from other site collections with REST/JSON?

http://blogs.msdn.com/b/officeapps/archive/2012/11/29/solving-cross-domain-problems-in-apps-for-sharepoint.aspx?CommentPosted=true#commentmessage

2
  • What is your POST message attempting to do, create a list or add a list item? What's stored in the fileData variable? Sep 1, 2013 at 19:10
  • it uploads a file to a sharePoint Document library. But it only lets me upload to the app host site. I will update the post to show the url
    – Hell.Bent
    Sep 2, 2013 at 20:53

1 Answer 1

2

See this post on How to: Access SharePoint 2013 data from remote apps using the cross-domain library. The message you send needs to go to the App Web but in it you need to indicate that you want it to be executed on the Host Web. You do this using SP.AppContextSite.

For example, the URL to get the Title of the Host Web would be:

appweburl + "/_api/SP.AppContextSite(@target)/web/title?@target='" + hostweburl + "'",

If you're not familliar with the terms App Web and Host Web, see Host webs, app webs, and SharePoint components in SharePoint 2013

1
  • It's working.. what I can't do is access sharePoint lists on other sites on our Domain.
    – Hell.Bent
    Sep 2, 2013 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.