SharePoint hosted app error log

Hi,
  I'd like to log the error in ULS log from sharepoint hosted app [Client side]. Is it possible, if yes, please let me know how to do it..
Balaji -Please click mark as answer if my reply solves your problem.

Hi,
You could write informations to the "App Error Log".
Have a look at these links :
http://exxlence.com/2013/01/07/add-logging-to-your-sharepoint-app-using-logcustomapperror-method/
http://sp2013.blogspot.fr/2013/01/sharepoint-apps-logging.html
Regards
Gilles Martinez
Twitter
Blog
Please mark as helpful/answer if this resolved your post

Similar Messages

  • 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

  • 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

  • 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

  • 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.

  • Create SharePoint hosted app when i debug project in IE browser getting error "Operation aborted" .

    Hi all,
    I am create SharePoint hosted app for SharePoint online. When i debugs project in IE browser getting error "Operation aborted".
     Please Suggest appropriate Way.
    Thanks
    Akash Anand 

    This happens sometimes if you are using third party library which IE does not support. Change the default browser of Visual Studio to Google Chrome and try.
    Let us know either it works or not
    Regards
    Khalil Kothia, PMP
    Blog

  • SharePoint hosted App that listens and log SharePoint Events

    Basically, what I need, is something that can listen to all events fired in SharePoint and write them to a custom list.
    I was thinking of making this as a SharePoint hosted app because it has to work on SP Online as well.
    The idea is then, to let a provider hosted app read the custom list every x minutes and do it's own logic depending on the events it reads from the custom list.
    So the question is, how do I catch all the events fired in SharePoint and should it be a SharePoint hosted app that does it?
    Any thoughts on how to solve this?
    Thanks.
    Thomas Bomann, simplySo

    Hi,
    According to your description, my understanding is that you want to track all the event fired in SharePoint .
    Listen to the events in SharePoint needs Server side code, see the article below:
    Programming Event Handling in Windows SharePoint Services
    In SharePoint hosted app, it needs to use Client Object Model, so there is no such Client API to meet the requirement.
    More information:
    JavaScript Client Object Model in SharePoint 2013
    Thanks
    Best Regards,
    Jerry Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • 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

  • How to get hostweb's site collection in SharePoint hosted app?

    I want display SharePoint site collection of host web in my SharePoint hosted app. I have used following code. 
    ExecuteOrDelayUntilScriptLoaded(callSharePoint, "sp.js");
    function callSharePoint() {
    hostweburl = getQueryStringParameter("SPHostUrl");
    appweburl = getQueryStringParameter("SPAppWebUrl");
    hostweburl = decodeURIComponent(hostweburl);
    appweburl = decodeURIComponent(appweburl);
    var scriptbase = appweburl + "/_layouts/15/";
    $.getScript(scriptbase + "SP.Runtime.js",
    function () {
    $.getScript(scriptbase + "SP.js",
    function () {
    //$.getScript(scriptbase + "SP.Taxonomy.js", function () { });
    $.getScript(scriptbase + "SP.RequestExecutor.js", execOperation);
    //Loads context, web and lists....
    function execOperation() {
    try {
    //create context for appweburl.
    context = new SP.ClientContext(appweburl);
    var factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
    context.set_webRequestExecutorFactory(factory);
    //get hostsite reference & load as web.
    appContextSite = new SP.AppContextSite(context, hostweburl);
    web = appContextSite.get_web();
    context.load(web);
    list = web.get_lists();
    context.load(list);
    webs = appContextSite.get_web().get_webs();
    context.load(webs);
    //webs = appContextSite.get_site().get_rootWeb().get_webs();
    //context.load(webs);
    context.executeQueryAsync(onWebsLoaded, onQueryFailed);
    catch (err) {
    alert(err.message);
    function onWebsLoaded(sender, args) {
    alert(list.get_count());
    var webEnum = list.getEnumerator();
    while (webEnum.moveNext()) {
    web = webEnum.get_current();
    alert(web.get_id());
    for (var i = 0; i < webs.get_count() ; i++) {
    subwebs = webs.itemAt(i);
    recursiveAll(subwebs);
    /* recursive call for web */
    function recursiveAll(cweb) {
    debugger;
    alert(cweb.get_title());
    var subwebs = cweb.get_webs();
    context.load(subwebs);
    context.executeQueryAsync(function (sender, args) {
    debugger;
    var webEnum = subwebs.getEnumerator();
    while (webEnum.moveNext()) {
    web = webEnum.get_current();
    alert(web.get_title());
    //recursive call for current web.
    recursiveAll(web);
    }, function () { debugger; alert('err'); });
    In this code I have get all the list of the Host web. But I am not able to get Host webs.
    Any of the when I load the Web it gives me the AppWebUrl not the host web.
    So I tried by using following code
    context = new SP.ClientContext(hostweburl);
    web = appContextSite.get_web();
    context.load(web);
    context.executeQueryAsync(onWebsLoaded, onQueryFailed);
    But it gives me error: unexpected response data from server
    Is there any other way to view all sites and sub sites of the host web in SharePoint hosted app?

    Hi,
    Since you are using a provider Hosted app if you want to get the current logged in name than do not use AppOnlyAccessToken else use AccessToken which is App + user Context AccessToken.
    then 
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;will return proper user Name.
    HttpContext.Current.User.Identity.Name will never return the user as this object is related to IIS server of your App Server not sharepoint.you should set this as Anonymous in case of provider hosted app.you can download the below sample which uses the AccessToken which has user name in it.https://code.msdn.microsoft.com/Working-provider-hosted-8fdf2d95
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • Permissions required to deploy an "SharePoint hosted App" using VS 2013

    Hello,
    I'm trying to deploy a SharePoint Hosted App to an OnPrem SP2013 server.
    When i hit F5 (from VS 2013) i get the below error:
    "Error occurred in deployment step 'Uninstall app for SharePoint': The local SharePoint server is not available. Check that the server is running and connected to the SharePoint farm."
    I'm added to the Farm Administrators group, site collection admin and to the admin group of the box. But i do not have any db_Owner permissions the the config / content database.
    Do I need DB Access to deploy the apps? Please advice. 
    Thanks,
    Keerth
    Keerth R

    >>Do I need DB Access to deploy the apps? Please
    advice.
    Yes, you need to have db_owner permissions for the account which you are using to deploy the apps.
    http://www.sharepoint-journey.com/app-development-in-sharepoint.html
    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

  • 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

  • Can't add images to announcements in SharePoint-hosted app in Office 365

    I tried something very simple:
    Create a new SharePoint-hosted app
    Add a new list to the app, based on the Announcements template
    Deploy the app to my Dev site on Office 365
    When I now add a new item (aka a new announcement) and try to add an image to the Body field, I encounter two errors (depending on whether I try to add an image from my Computer or from SharePoint)
    Adding from my computer gives me an unexpected error:
    Adding from SharePoint shows me a structure of all the apps in my hostweb, but no way to upload an image either to the hostweb or the appweb:
    Is it not possible to add images to a Rich Text field in a list in an app?

    Hi Rene,
    For inserting any image from you computer to you App web, you need to create a separate picture library in your app web manually i.e. in your SharePoint hosted app add a new list item, under list settings window choose "create a list instance
    base on existing list template" and in the drop down select
    picture library. Now deploy the app and try again.
    Generally when we insert any image from our computer to a SharePoint rich text field, the image gets upload in one of the document libraries, but this option is not available in the newly created app web, as it doesn't contains any separate library..
    For you next error, make sure that in the app manifest you are providing
    read access on the web, this will resolve you second problem.
    Hope it helps you.....

  • SP is undefined in sharepoint hosted app client Webpart

    Hello All,
    For a client web part in sharepoint hosted app, I am getting the following error
    "SP is undefined".
    My code is bel0w
       <script
     type="text/javascript"
     src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js">
    </script>
        <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
         <script  type="text/javascript" src="/_layouts/sp.core.js"></script>
        <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
            <script type="text/javascript" src="/_layouts/15/sp.js"></script>
        <script type="text/javascript">
            'use strict';
            $(document).ready(function () {
                        ExecuteOrDelayUntilScriptLoaded(loadConstants, "sp.js");
                    var  clientContext = SP.ClientContext.get_current();
                   var  web = clientContext.get_web();
    </script>     ....
    I am getting the error ExecuteOrDelayUntilScriptLoaded is undefied. This script is in client Web part
    Any help is appreciated.
    Vishnu

    Thanks for the reply Geetanjali.
    var  clientContext = SP.ClientContext.get_current();
     var  web = clientContext.get_web();
    These two lines of code is supposed to be inside "loadConstants" method.
    After changing the code as below, I am able to get SPClientContext and SPWeb.Also, host and appweb url as well
    <script
    type="text/javascript"
    src="../Scripts/jquery-1.6.2.min.js"></script>
     <script
    type="text/javascript"
    src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
     <script
    type="text/javascript"
    src="../Scripts/App.js"></script>
    $(document).ready(
        function () {
    var spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
          var appWebUrl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
    var layoutsRoot = spHostUrl + '/_layouts/15/';
            $.getScript(layoutsRoot +
    "SP.Runtime.js",
    function () {
                $.getScript(layoutsRoot +
    "SP.js", loadConstants);
    function loadConstants() {
                context =
    new SP.ClientContext.get_current();
                web = context.get_web();
    Thanks
    Vishnu
    dfd

  • Deployed lists in a SharePoint hosted app use the wrong content type.

    I am using Visual Studio Ultimate 2013 to deploy a SharePoint hosted app to my SharePoint 2013 development environment. 
    I have created 2 lists, one of which is using a custom content type with custom columns and the other is just a simple custom list definition and instance, all of which are deployed inside the same feature.
    However when I go to the simple list, it is using the content type from the other list, even though in the schema.xml shows that it is not supposed to use this content type. I have checked the content type ID and it is not referencing my custom content type,
    but for some reason the list is using that content type.
    I remember seeing this same issue a few months ago while creating a SP2010 sandbox solution. It could well be something I'm doing wrong when creating the lists/content type.
    Steps to recreate this issue:
    Create a SharePoint hosted app in VS
    Create some custom fields
    Create a custom content type
    Create a list based on that content type
    Create another list not based on the content type
    Delete feature that VS creates for the second list and add the list def and instance to the main feature (containing the other list and content type)
    Deploy and go to second list, note that it has the custom fields from the first list.
    Any advice on what to do about this would be great. I have tried deleting the list and recreating it in VS several times but that didn't work.
    Thanks
    David

    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

  • 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

Maybe you are looking for

  • IBook G3 300 mHz battery won't charge

    I have an iBook G3 with a 300 mHz processor (aqua clam shell). I replaced the battery from a reputable supplier but is still does not charge the battery. I tried the usual upgrades to software, battery reset 2.0, reset PRAM, cleaned all contacts, and

  • AR invoice with Multiple lines

    Hello, I'm loading AR invoice using Autoinvoice Import Program. This works fine for invoices with single lines. When I have invoices with more than one row it errors out. The Autoinvoice program completes with Error. For loading multiple lines to the

  • Airport extreme not compatible with xbox live?

    Hello, Ive had this problem for a long while now and are getting desperate. Basically when i go on xbox live the connection is really really bad. It's not all the time, rarely it will work fine but most of the time the connection is awful. I know the

  • Dina, Differenc Betn R12 Oracle Projects Vs Oracle 11g Fusion Project Portf

    Hi Dina / Experts, Can anyone of you help me in getting the product features differences between R12 Oracle Project Suite Vs Oracel 1Fusion 11g Project Portfolio Management? can you please provide me reference document / link / RCD / PPT if possible.

  • Is apple's magic mouse compatible with windows that has Bluetooth?

    Is apple's magic mouse compatible with windows that has Bluetooth?