Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

WebAPI : Unable to access custom entity using Web API.

Posted on by 335

I am struck here badly, Have been trying different options but no use.

I have two entities and have to create an association between these two.

I have the following code to achieve this.

 var clientURL = parent.Xrm.Page.context.getClientUrl();  
    var req = new XMLHttpRequest()    
    req.open("POST", encodeURI(clientURL + "/api/data/v8.0/new_experiencetopgs"), true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
        if (this.readyState == 4 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 204) {
                var accountUri = this.getResponseHeader("OData-EntityId");                
            }
            else {
                var error = JSON.parse(this.response).error;
            }
        }
    };
    var experiencetopgs = new Object();
    //String Field
    experiencetopgs.new_name = Math.random()+"ExperienceGroup";
    var experienceId =parent.Xrm.Page.data.entity.getId().substring(1, 37);
    //Lookup
	
    experiencetopgs["new_exppgexperience@odata.bind"] = "/***_experiences("+experienceId+")"
	experiencetopgs["new_exppracticegroup@odata.bind"] = "/new_experiencetopgs("+practiceGroupId+")"
	jObj=JSON.stringify(experiencetopgs).replace(/ /g,'');
    var response = req.send(jObj);


When it comes to ***_experiences, it's not accessible, I tried to directly access this entity using web API URL.

server/.../v8.0***_experienceses

Response : 

{
  "error":{
    "code":"","message":"Resource not found for the segment '***_experienceses'.",
"innererror":{ "message":"Resource not found for the segment '***_experienceses'.",
"type":"Microsoft.OData.Core.UriParser.ODataUnrecognizedPathException",
"stacktrace":"at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.ParsePath(ICollection`1 segments)\r\n at Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n at Microsoft.OData.Core.UriParser.ODataUriParser.Initialize()\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath, ODataUriResolverSetttings resolverSettings, Boolean enableUriTemplateParsing)\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)" } } }

*This post is locked for comments

  • CrmMad Profile Picture
    CrmMad 65 on at
    RE: WebAPI : Unable to access custom entity using Web API.

    Hello prashanth.kamasamudram,

    I had the same error.

    I resolved the problem open the metada with XRMtoolbox and there I can my setentityname was "why_pricingruleses" instead "why_pricingrules". I don't know why the system save the plural name instead singular name

    I resolved the problem with this

    Best Regards

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: WebAPI : Unable to access custom entity using Web API.

    Hi Prashanth,

    Try using the following URL.

    url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_experiencetopges"

    Try using the plural name of the entity.

    Can you share a screenshot of the custom entity information? 

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: WebAPI : Unable to access custom entity using Web API.

    Hi Prashanth,

     I did not try it, but maybe this would work:

    - Add that entity to a new solution

    - Export your solution

    - Open customizaitons.xml

    - Find <EntitySetName> tag

    - Add your plural name there

    - Repackage and import back to CRM

     If, somehow, you can't find EntitySetName tag at all, it follow "attributes/>" in my case, so try adding it then:

             </attributes>  

             <EntitySetName>tcs_lookupconfigs</EntitySetName>

             <IsDuplicateCheckSupported>0</IsDuplicateCheckSupported>

    PS. I was sure I saw this link just the other day.. could not find it right away - some useful reading there, too:

    community.dynamics.com/.../crm-2016-web-api-and-plural-names

  • RE: WebAPI : Unable to access custom entity using Web API.

    Hi Alex,

    It seems like this is the reason Web API is unable to find the reference to Entity.

    Is there any way to update this and give proper name?

    Kind Regards

    Prashanth

  • RE: WebAPI : Unable to access custom entity using Web API.

    Hi Alex,

       Checked it, its showing null.

    Kind Regards

    Prashanth

  • RE: WebAPI : Unable to access custom entity using Web API.

    Thank you for ur response, I did import this solution and generated the code.

    Following is the code which got generated.

    var entity = {};
    
    entity["new_exppgexperience@odata.bind"] = "/null()";
    
    entity["new_exppracticegroup@odata.bind"] = "/new_practicegroups()";
    
    entity.new_name = "";
    
    $.ajax({
    
       type: "POST",
    
       contentType: "application/json; charset=utf-8",
    
       datatype: "json",
    
       url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/new_experiencetopgs",
    
       data: JSON.stringify(entity),
    
       beforeSend: function(XMLHttpRequest) {
    
           XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
    
           XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
    
           XMLHttpRequest.setRequestHeader("Accept", "application/json");
    
           XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    
       },
    
       async: false,
    
       success: function(data, textStatus, xhr) {
    
           var uri = xhr.getResponseHeader("OData-EntityId");
    
           var regExp = /\(([^)]+)\)/;
    
           var matches = regExp.exec(uri);
    
           var newEntityId = matches[1];
    
       },
    
       error: function(xhr, textStatus, errorThrown) {
    
           Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
    
       }
    
    });


    If you see at the third line of code, we got null in place of the entity name.

    entity["new_exppgexperience@odata.bind"] = "/null()";

    the entity is there and is being used but is not accessible by external code it seems.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: WebAPI : Unable to access custom entity using Web API.

    Hi,

      did you try to see your custom entity "set" name in the XrmToolBox Metadata Browser?

    2450.1.PNG

      I believe that's the name you should be using, so it might be different somehow

  • Verified answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: WebAPI : Unable to access custom entity using Web API.

    I know you stated that you checked the schema names. Are they in the correct case as I think its case sensitive.

    Or you could use the CRM REST Builder to generate the code for you: github.com/.../CRMRESTBuilder

  • RE: WebAPI : Unable to access custom entity using Web API.

    I have also tried to install metadata browser and check for entity name and schema names, Everything is correct and also tried using the plural name. nothing is working.

    IS there any chance of some metadata setting for an entity which is blocking wep api from accessing this entity?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans