locked
401 Unauthorized webservice call RRS feed

  • Question

  • Hi

    I have a dynamics crm 2013 development enviroment with a organization running with ADFS.

    I try to locally develop a JS site that i later will embed in the crm using an iframe. Somehow, whenever i try to call the crm service (to retrieve some date) i get an unathorized error. This is my jquery request:


      $.ajax({
      type: "GET",
      contentType: "application/json; charset=utf-8",
      datatype: "json",
      url: OdataEndpoint + "/" + entityName + "(guid'" + id + "')",
      beforeSend: function (XMLHttpRequest) {
       XMLHttpRequest.setRequestHeader("Accept", "application/json");
      },
      success: function (data, textStatus, XmlHttpRequest) {
       if (successCallback) {
        successCallback(data.d, textStatus, XmlHttpRequest);
       }
      },
      error: function (XmlHttpRequest, textStatus, errorThrown) {
       if (errorCallback)
        errorCallback(XmlHttpRequest, textStatus, errorThrown);
       else
        errorHandler(XmlHttpRequest, textStatus, errorThrown);
      }
     });
        }
      }
    The odata endpoint url looks like this:
    https://org.domain.com/XRMServices/2011/OrganizationData.svc/myentitySet(guid'%7B0111AAE5-74CC-E311-93F8-E41F13BE2EFC%7D')



    I also tried to call the internal url or the ip itself. With IE i get the 401 and with Chome and Firefox i even get a 404 (not found). When i open the url directly in the browser, it works perfectly an i get a response.

    Any ideas?

    Kind regards

    Daniel


    Wednesday, April 30, 2014 8:40 PM

All replies

  • As you are executing this code from outside CRM Pages, it will need to set authentication explicitly. If your intent is to run it as sandalone paeg out side CRM then following this url http://msdn.microsoft.com/en-us/library/dn531009(v=crm.6).aspx

    Else upload it as Web resource and see if you still get 401 error.

    Thanks

    Mak

     

    MaKeer | myencounterwithcrm.wordpress.com | CRM2011 User Settings Utility | CRM2011 Lookup Preview | CRM2011 Lookup Attribute Mapping | CRM2011 TreeView Control (Beta) | CRM2011 N:N Entity View (Beta) | CRM 2011 Global Quick Search (Beta)

    Wednesday, April 30, 2014 11:23 PM
  • Thanks for your reply. Yes i want this code to be executed outside the crm (so that i dont have to upload it after every change). I read the arcticel but dont get how to authenticate in the JS enviroment. Can you provide an example?


    Daniel

    Thursday, May 1, 2014 7:52 AM
  • If the code is to be executed outside of CRM, then it is not trivial to authenticate the user, and to pass the token to the CRM web services. If the only reason to execute the code outside of CRM is to simplify deployment of changes, then you'll find that it would be much more work to manage the authentication compared to the deployment overhead of updating code as a web resource in CRM

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, May 1, 2014 5:16 PM
    Moderator