Issue with REST POST call: CopyTo in a SharePoint hosted App not working

Hi Community
I have been really struggling to get a cross domain copy to work both in an App or even using REST Tools such as Postman or Google Advanced REST Client. 
Ok there are various blog posts by Scott G et al.  that shows how you can post say in a single domain.  Now that's fairly straight forward
in my case I took a .apsx page and added the following lines of code - Checkin - refresh and great the file gets copied via  the document ready function
(document).ready(function () {
alert('ready!');
var src = "/appsdev/Shared Documents/SrcDoc.docx";
var dst = "/appsdev/Shared Documents/DestDocCopiedByRestTestASPXPage.docx";
jQuery.ajax({
type: "POST",
contentType: "application/json;odata=verbose",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfilebyserverrelativeurl('" + src + "')/copyto(strnewurl='" + dst + "',boverwrite=true)",
success: function (data, errorCode, errorMessage) {
alert('Success: copied the damn file');
var jsonObject = JSON.parse(data.body);
var jsonObjectText = JSON.stringify(jsonObject);
error: errorHandler
Now I make the call in my SharePoint hosted App and I simple can' t  get this to work. Fiddler doesn't exactly help a lot
  var src = "/appsdev/Shared Documents/SrcDoc.docx";
  var dst = "/appsdev/Shared Documents/DestDocCopiedByMyApp.docx";
    var urlWriteLocalFileDebug = appweburl +
   "/_api/SP.AppContextSite(@target)/web/Getfilebyserverrelativeurl('" + src + "')/copyTo(strNewUrl='" + dst + "', bOverWrite=true)?@target='" + hostweburl + "'";
executor.executeAsync(
method: "POST",
contentType: "application/json;odata=verbose",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
url: urlWriteLocalFileDebug,
success: function (data, errorCode, errorMessage) {
alert('Success: copied the damn file');
var jsonObject = JSON.parse(data.body);
var jsonObjectText = JSON.stringify(jsonObject);
error: errorHandler
I can happily run a GET and see the properties of my file but POST no way.   Curriously, when I try to run the same command for say Google Advanced Rest Client I get nowhere
Is this a new mensa test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
Freelance consultant

Hi
I have now tested against a trail Office  365 Developer site and I had to make a few adjustments
- change the url
- change the target to SharePoint Onlne
- change the url 
I still wasn't happy so I created a new SharePoint Hosted app and pointed at the above developer site.  I copied my CrossDomainExec.js and stripped all my code except my CopyItemInSameLIbrary method which hasn't changed since I created this post. 
- changed the App Manifest permissions to Web -full Control ( was previously tenant)
I still got errors which is really painful as you don't even see the POST request in Fiddler
The URL used for my POST is as follows ( note host URL is fictitious)
"https://myapphell-547d8061d39e38.sharepoint.com/sites/appsdev/RESTTestSHA/_api/SP.AppContextSite(@target)/web/Getfilebyserverrelativeurl('/sites/appsdev/Shared Documents/SrcDoc.docx')/copyTo(strNewUrl='/sites/appsdev/Shared Documents/DestDoc.docx', bOverWrite=true)?@target='https://myapphell.sharepoint.com/sites/appsdev'" String
Ran the app a second time and now I see......Wow it WORKS!!!!!! ..Can't be true can it?
.... next I will switch the target url to my on prem farm to see if this still works so watch this space!
Daniel
Freelance consultant

Similar Messages

  • I have a problem with my MacBook Pro is the almost of my app not working at all like a app store and terminal and other important apps please if u can help me as fast as you can cuz i don't wanna format it that's why am on Mac now not win ?

    i have a problem with my MacBook Pro is the almost of my app not working at all like a app store and terminal and other important apps please if u can help me as fast as you can cuz i don't wanna format it that's why am on Mac now not win ?

    Abdussalam.A,
    you mentioned that Terminal does not work at all for your MacBook Pro. What currently happens when you run Terminal? In what way does it not work?

  • OnPremise: Sharepoint Hosted App gives 401 unauthorized error while accessing UserProfile Rest Service

    Hi All,
    I have SharePoint hosted app deployed on On-Premise using(F5) which reads User Profile data consumes WCF(Hosted on same server) through REST API to insert data in to SQL DB(Different server).
    SharePoint hosted app was working as expected and suddenly it started asking for credential and not login(any user) to the application landing page.
    Checked SharePoint Logs, IIS Logs and Windows log but did not get any clue.
    WCF is accessible, User Profile access is also happening but not sure what changes done on server or infra level which causing this issue.
    I have an On-Premise Environment for SharePoint 2013. where we have created SharePoint hosted app which calls "http:///_api/SP.UserProfiles.PeopleManager/GetMyProperties" to get current user's data. but this gives me 401 unauthorized error.
    Notes:
    I had given read permission to user profile and full control to sitecollection in appmanifest. If I run this app on Office 365 developer site it works fine, but on premise environment it give 401 error.
    On premise environment when I deploy this app 3 times it prompt for  credential and finally gives the following error
    Error message after login 3 times:
    {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access
    denied. You do not have permission to perform this action or access this resource."}}}
    -Lovekush Kumar 

    Add your site (http://*.app.contoso.com) to your local intranet sites in IE. 
    "app.contoso.com" is app domain.
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • How to get inputted value in a RTE field on custom page and submit by REST call in 'Sharepoint hosted app'.

    Hi I am facing the three questions below.
    1. How to use default RTE in custom page in Sharepoint hosted app.
     I saw the article of Rich text Editor (ribbon based) in a webpart in SharePoint 2013 and tried it. But it did not work well. I guess it needs code-behind setting, however sharepoint hosted app does not support code-behind.
    Does anybody know how to do this?
    2. In above case, I placed the below code on custom page and tried to get the field's value when submit button was clicked.
    <SharePoint:InputFormTextBox ID="rftDefaultValue"
    RichText="true"
    RichTextMode="FullHtml" runat="server"
    TextMode="MultiLine" Rows="5">
    </SharePoint:InputFormTextBox>
    In debugger, the returned value was 'undefined'.
    var note = $('#hogehoge').val();
    Is it possible to get the RTE value? If yes, please let me know how to do this.
    3. I need to submit the RTE value using REST call.
    In this
    article in MSDN, the item creation sample treats single line text field. Does anybody know the sample for RTE?

    Hi,
    According to your description, you might want to use Rich Text Editor control in your SharePoint hosted app.
    First of all, I would suggest you post one question in one thread to make it easier to be discussed, which would also help you get a quick solution.
    Though we can add this control into a SharePoint hosted app, however, as we can’t add code behind for it, plus with the potential compatibility issues in different
    browsers, I would suggest you use other JavaScript Rich Text Editor plugins instead.
    Two JavaScript Rich Text Editor plugins for your reference:
    http://quilljs.com/
    http://nicedit.com/
    If you want to submit the value of Rich Text Editor control to a SharePoint list using REST call, since the content in the Multiple Line of Text column is wrapped
    with nested HTML tags, the similar requirement would also be applied to the content to be submitted.
    Here is a code snippet about how to update a Multiple Line of Text column for your reference:
    updateListItem(_spPageContextInfo.webAbsoluteUrl, "List018", 1);
    function updateListItem(siteUrl, listName, itemId)
    var itemType = GetItemTypeForListName(listName);
    var item = {
    "__metadata": { "type": itemType },
    "MultiTextEnhanced": "<div><a href='http://bing.com/'>Bing</a><br></p></div>",
    "Title": "123"
    $.ajax({
    url: siteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemId + ")",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {
    console.log(data);
    $.ajax({
    url: data.d.__metadata.uri,
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: JSON.stringify(item),
    headers: {
    "Accept": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
    "X-HTTP-Method": "MERGE",
    "If-Match": data.d.__metadata.etag
    success: function (data) {
    console.log(data);
    error: function (data) {
    console.log(data);
    error: function (data) {
    console.log(data);
    // Getting the item type for the list
    function GetItemTypeForListName(name)
    return"SP.Data." + name.charAt(0).toUpperCase() + name.slice(1) + "ListItem";
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Patrick Liang
    TechNet Community Support

  • Getting error while uploading multiple files in sharepoint hosted app in 2013 with REST API

    Hi All,
    In one of my tasks, I was struck with one issue, that is "While uploading multiple files into custom list with REST API".
    Iam trying to upload multiple files in library with REST calls for an APP development, my issue is if i wants to upload 4 image at once its storing only
    3 image file and further giving "Conflict" error". Below is the attached screenshot of exact error.
    Error within screenshot are : status Code : 409
    status Text :conflict
    For this operation i am uploading different files as an attachment to an list item, below is the code used for uploading multiple files.
    my code is
    function PerformUpload(listName, fileName, listItem, fileData)
        var urlOfAttachment="";
       // var itemId = listItem.get_id();
        urlOfAttachment = appWebUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items(" + listItem + ")/AttachmentFiles/add(FileName='" + fileName + "')"
        // use the request executor (cross domain library) to perform the upload
        var reqExecutor = new SP.RequestExecutor(appWebUrl);
        reqExecutor.executeAsync({
            url: urlOfAttachment,
            method: "POST",
            headers: {
                "Accept": "application/json; odata=verbose",
                "X-RequestDigest": digest              
            contentType: "application/json;odata=verbose",
            binaryStringRequestBody: true,
            body: fileData,
            success: function (x, y, z) {
                alert("Success!");
            error: function (x, y, z) {
                alert(z);

    Hi,
    THis is common issue if your file size exceeds 
     upload a document of size more than 1mb. worksss well for kb files.
    https://social.technet.microsoft.com/Forums/office/en-US/b888ac78-eb4e-4653-b69d-1917c84cc777/getting-error-while-uploading-multiple-files-in-sharepoint-hosted-app-in-2013-with-rest-api?forum=sharepointdevelopment
    or try the below method
    https://social.technet.microsoft.com/Forums/office/en-US/40b0cb04-1fbb-4639-96f3-a95fe3bdbd78/upload-files-using-rest-api-in-sharepoint-2013?forum=sharepointdevelopment
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Our software vendor tells to use FF 3.5.1. because of some printer issues with their web based program. How safe is it to work with FF 3.5.1 in 2012?

    Our software vendor tells to use FF 3.5.1. because of some printer issues with their web based program. How safe is it to work with FF 3.5.1 in 2012?

    Thanks for the reply. I'll have a look at your solution.

  • Having issues with low memory that is causing some of my apps to crash, need help please !!!

    Having issues with low memory that is causing some of my apps to crash, need help please !!!

    Is the device actually showing low memory errors?
    What is really occurring?
    Basic troubleshooting from the User's Guide is reset, restart, restore (first from backup then as new).  Has any of this been tried?

  • Issue with Workflow in a SharePoint-hosted App Application

    Hi,
    I have created a Sharepoint-hosted app which has a list workflow in it. After I deploy it to the sharepoint server,  I can not find any workflow under the associated list.
    However, I did have target list associated with workflow in workflow project property.  
    (My app and worflow is developed in VS 2012)
    I have searched the forum and found some similar question. However, all of them don't have useful answers.....
    Can anyone give me some help~?

    Hi Baron123,
    I can reproduce your scenario, that create an app with list, and add a workflow associates with it, the workflow is not working, that seems doesn’t associates successfully.
    Before I can tell why this happens, I found a helpful blog about keeping the list definitions and workflow definitions separate, use Handle APP installed event receiver to wire up a workflow to lists in app web or host web.
    As it is not a good solution to deploy the list and workflow in the same app solution, because that if you redeploy the app the date will be lost, the list will be new created, so I would suggest you to reference the blog, check whether this can meet your
    requirement.
    SharePoint Apps and Workflow:
    http://jonfancey.azurewebsites.net/2013/03/22/SharePointAppsAndWorkflow.aspx
    Thanks,
    Qiao Wei
    TechNet Community Support

  • Sharepoint-Hosted App giving FORBIDDEN error when i use REST Api

    Hi,
    I have created a sharepoint hosted app which will create Team site on button click.
    I used REST Api  and  NAPA Tool to develop this app.
    Napa tool gives to things ClientWebpart.aspx and Default.aspx.
    When i run my Default.aspx code is working fine but ClientWebpart.aspx is giving FORBIDDEN error when i am trying to create site.
    Below is the code which i used to create site
    code:
    var hostweburl;
    var appweburl;
    $(document).ready(function () {
    hostweburl= decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
    function createSPWeb() {
    $.ajax(
    url: appweburl +
    "/_api/SP.AppContextSite(@target)/web/webinfos/add?@target='" +
    hostweburl + "'",
    type: "POST",
    data: JSON.stringify(
    'parameters':
    '__metadata': { 'type': 'SP.WebInfoCreationInformation' },
    'Url': 'RestSubWeb',
    'Title': 'RestSubWeb',
    'Description': 'REST created web',
    'Language': 1033,
    'WebTemplate': 'sts#0',
    'UseUniquePermissions': false
    headers: {
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val()
    success: successHandler,
    error: errorHandler
    NOTE:This is on sharepoint online.
    Please help
    Regards,
    sudeep

    So in the app you are testing, are you using the FQDN or the NetBIOS name? Bad practice but could you test with both (hard code the absolute URL for testing purposes) then retest your app?
    If you are making a web part based on the new app model this will be an "app part" and probably have the same issues you are experiencing. If this is for something internal rather than a product you are developing to resell then the script editor /
    content editor web part approach could work for you.
    Paul
    Paul Mather | Twitter |
    http://pwmather.wordpress.com | CPS

  • Unable to add aspx file to document library using REST and JSOM in SharePoint Hosted App

    Hi,
    I am unable to add an aspx file to document library.  I was actually trying to create a WIKI page and upload to Pages library but that wasn't working so I tried simple document library.  It keeps failing with Access Denied error.  I have checked
    the blocked types and aspx is not included.  I can upload it directly from the browser so that shouldn't be the case.  I have read that it can be achieved with CSOM but I need this to work with a SharePoint Hosted App.  Here is my JSOM:
    factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        oWeb = appContextSite.get_web();
        oList = oWeb.get_lists().getByTitle('Documents');
        fileCreateInfo = new SP.FileCreationInformation();
        fileCreateInfo.set_url("mywiki.aspx");
        fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
        fileContent = "<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\"
    %> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %>";
        for (var i = 0; i < fileContent.length; i++) {
            fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
        newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);
        context.load(newFile);
        context.executeQueryAsync(function () {
            alert('yo');
        }, function (sender, args) {
            alert(args.get_message() + '\n' + args.get_stackTrace());
    If I change the file extension to "txt", it works.  Same with REST implementation, it works with "txt" but fails with "aspx".  Maybe what I am trying to do will not work using JSOM or REST.  Any suggestions?  Your
    help is always appreciated.
    Regards,
    kashif

    Your code works fine in both my on-premises and SharePoint Online. I have given the app full control, so I suspect this is a permissions issue. I would check your permissions on your appmanifest. Must be something to do with publishing permissions. Try
    giving full control and work the permissions down.
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • Call EWS from SharePoint 2013 SharePoint Hosted App (JavaScript) in Office 365

    I am trying to call the exchange web service (EWS) of an exchange online server from a SharePoint hosted app. I am limited thus to the use of Javascript. During my call i am always getting an access denied error.
    The body of the SOAP request is good since I have tested it using a client application, but I am not being able to get it to work via a jquery ajax call. I am sure that this is an authentification issue and I have no problem sending the credentials during
    the call. I have added them in the header. This is what I have ended up doing but still no luck.
    functionGetUnReadEmailCount() {
    varsoapPacket = "<?xml version='1.0' encoding='utf-8'?>"+
    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'>"+
    '<soap:Header>'+
    '<wsse:Security>'+
    '<wsse:UsernameToken>'+
    '<wsse:Username>******</wsse:Username>'+
    '<wsse:Password>******</wsse:Password>'+
    '</wsse:UsernameToken>'+
    '</wsse:Security>'+
    '</soap:Header>'+
    "<soap:Body>"+
    "<FindItem xmlns='http://schemas.microsoft.com/exchange/services/2006/messages' xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'Traversal='Shallow'>"+
    "<ItemShape>"+
    "<t:BaseShape>IdOnly</t:BaseShape>"+
    "</ItemShape>"+
    "<IndexedPageItemView MaxEntriesReturned='50' Offset='0' BasePoint='Beginning' />"+
    "<Restriction>"+
    "<t:IsEqualTo>"+
    "<t:FieldURI FieldURI='message:IsRead' />"+
    "<t:FieldURIOrConstant>"+
    "<t:Constant Value='false' />"+
    "</t:FieldURIOrConstant>"+
    "</t:IsEqualTo>"+
    "</Restriction>"+
    "<ParentFolderIds>"+
    "<t:DistinguishedFolderId Id='inbox' />"+
    "</ParentFolderIds>"+
    "</FindItem>"+
    "</soap:Body>"+
    "</soap:Envelope>";
    $.support.cors = true;
    $.ajax({
            url: "https://outlook.office365.com/EWS/Exchange.asmx",
            type: "POST",
            dataType: "xml",
            data: soapPacket,
            complete: processResult,
            error: OnError,
            contentType: "text/xml; charset=\"utf-8\""
    Any help is highly appreciated.
    Thanks.
    Elie

    Hi Elie,
    Since this forum is discussing about Developing Apps for Office 2013, and your issue is more related about Exchange development. I will move this thread to the more related forum.
    Reference:
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exchangesvrdevelopment
    Thanks for your understanding.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I have a problem with iphone 4s...is ringing but another sounds not working....please help me!!!

    i have a problem with iphone 4s...is ringing but another sounds not working....please help me!!!

    Hi pystyke,
    Welcome to Apple Support Communities.
    You may find these links helpful with troubleshooting the audio issue you're experiencing:
    iPhone Assistant
    http://www.apple.com/support/iphone/troubleshooting/
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/TS2802
    Best,
    Jeremy

  • SharePoint hosted app issue - This page cannot be displayed

    Hi All, need help on below issue, 
    When I deploy SharePoint hosted app from Visual Studio 2012, it generated app web URL and that opens the app properly. But, if I upload .app file after
    publish in Visual Studio 2012 to App Catalog and added new app based on my SharePoint hosted app. When try to click on app, saying ‘This page can’t be displayed’ in internet explorer. I don’t think so it will be issue with app domain as the app working fine
    if deploy from visual studio. Thanks in advance for your help.

    It may still be an issue with the app domain, actually with DNS.  When you deploy from VS 2012 it automatically adds the appropriate DNS entries to the Hosts file on your VS 2012 PC.  That way the App domain can be resolved and you can reach the
    site.  When you deploy by uploading to the App Catalog that entry in the HOsts file is not created.  Instead you should ahve already added the App domain and a wildcard entry to the DNS server used in your network.  If that wasn't done then
    you will get exactly the behavior you describe.
    Take a look at the section on DNS in the following article.  Make sure you've followed all the instructions.
    http://technet.microsoft.com/en-us/library/fp161236(v=office.15).aspx
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Error when trying to retrieve Document Library in Sharepoint Hosted App using REST

    I have created the following REST request in order to retrieve the root folder of a Document Library added to a Sharepoint Hosted App
    getProductDocumentFolder: function () {
    $.ajax({
    url: _spPageContextInfo.webServerRelativeUrl +
    "/_api/web/GetFolderByServerRelativeUrl('/Lists/ProductDocuments')",
    type: "GET",
    headers: {
    "accept": "application/json;odata=verbose",
    success: function () {
    alert("Success!");
    //REST.Operator.readAll();
    error: function (err) {
    alert("Oops, error!");
    alert(JSON.stringify(err));
    The Document Library was added to the App from the Add > New Item menu in Visual Studio. I selected List and Selected Document Library from the Create a customizable list... dialog. The list is defined as shown in the picture below.
    I get the generic error "Value does not fall within the excepted range".
    I have tried both 
    "/_api/web/GetFolderByServerRelativeUrl('/Lists/ProductDocuments')"
    and
    "/_api/web/GetFolderByServerRelativeUrl('/ProductDocuments')"
    for the Document Library URL both I get the same error in both cases.
    What am I missing here?

    Problem solved. 
    It turns out there should be NO leading '/' in the relative URL despite the example shown in http://msdn.microsoft.com/en-us/library/office/dn292553.aspx#Folders with "/Shared Folder".
    The correct GetFolderByServerRelativeUrl-parameter in my case is 'Lists/Productdocuments'.
    Unsure whether example is wrong or if it applies to other cases than mine.

  • Mail flooded with unread messages/FB app not working...linked?

    All at once my Mail inbox has over 2,400 messages and Facebook app not working. I have not updated the last 2 updates bc of storage, but don't know why yesterday it decided to have a problem with that? Any ideas what's going on and how to fix it?

    After Googling this issue to death, I finally clicked on the ? icon in the mail preferences panel. Apparently this is working as intended:
    Display unread messages with bold font:
    Display unread messages in bold font in classic layout, to help you distinguish them from messages you have read.

Maybe you are looking for