Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
    
What is your POST message attempting to do, create a list or add a list item? What's stored in the fileData variable? –  Rob Windsor Sep 1 '13 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 –  cyberpine Sep 2 '13 at 20:53
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
It's working.. what I can't do is access sharePoint lists on other sites on our Domain. –  cyberpine Sep 2 '13 at 21:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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