Development

Why my action is not available through WebApi?

Recently I was working on task where I wanted to use Actions through JavaScript. It was a pretty usual task until I came calling of an action through WebApi. I was able to call that action through SOAP endpoint but every call through WebApi threw an error with message “Resource not found for the segment ‘new_MyAction’.

My action had couple of simple (strings and integers) input parameters and had to return one string and one EntityCollection in result. To make action available through WebApi I had to remove all outputs except EntityCollection.

Let’s separate all types of arguments into two groups – simple (boolean, datetime, decimal, float, integer, money, picklist, string) and complex (EntityReference, Entity, EntityCollection). You can have any combination of simple output parameters or single complex output parameter to make your action available for WebApi. In other words if you combine complex output parameter with any other one (including another complex output parameter) your action becomes unavailable for WebApi calls.

To check availability of your action you can use metadata url:

CRM Online –  https://yourorgname.crm.dynamics.com/api/data/v8.1/$metadata

On-Premise with IFD configured – https://yourorgname.yourdomain.com/api/data/v8.1/$metadata

On-Premise without IFD configured – http://yourcrmserver/yourorgname/api/data/v8.1/$metadata

Just open metadata url in browser, wait till page is loaded and hit Ctrl-F to find action you want to check:

ActionAvailability

11 Comments on “Why my action is not available through WebApi?

    1. Hello Pavel,
      I have not. May be it’s a good idea to post it to CRMIdeas portal. I was able to find a workaround – I just added all additional information I need as a last element of collection and it worked fine.

  1. Has anyone tried to return one EntityCollection from the CustomAction with different entity types ?
    I’m doing that, but I get this error when calling the Custom Action (Returning an EntityCollection with just one entity type worked fine):

    “error”:{
    “code”:””,”message”:”‘select’ and ‘expand’ cannot be both null or empty.”,”innererror”:{
    “message”:”‘select’ and ‘expand’ cannot be both null or empty.”,”type”:”System.ArgumentException”,”stacktrace”:” at System.Web.OData.Query.SelectExpandQueryOption..ctor(String select, String expand, ODataQueryContext context, ODataQueryOptionParser queryOptionParser)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataEntityTypeSerializer.CreateSelectExpandNode(EntityInstanceContext entityInstanceContext)\r\n at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType)\r\n at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n— End of stack trace from previous location where exception was thrown —\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.d__1b.MoveNext()”
    }

    1. Hello,
      Yes, I experienced similar issue as well. Everything worked fine when I used SOAP calls but for WebApi it doesn’t work well.
      I ended up with changing output parameter to string and I serialized response as a JSon string and deserialized it back on client side. Worked like a charm.

  2. I will vote this up as well.
    We are seeing issues with our custom actions not showing up in the Metadata for the webapi. Only the actions which were imported from a solution do not show up in the Web Api metadata. If the action is created in the CRM instance, it shows up in the metadata.

  3. Hi Andrii. Not sure how you solved this. I have a bound action and no matter how I try to address it, I get the same error “Resource not found for the segment ‘cfc_ActivateaQuote'”. The URL’s I have passed in are:
    “https://cfccrm.crm.dynamics.com/api/data/v9.0/Microsoft.Dynamics.CRM.cfc_ActivateaQuote”
    “https://cfccrm.crm.dynamics.com/api/data/v9.0/cfc_ActivateaQuote”

    I looked at the metadata as suggested and do not see the Action name anywhere.

    1. Hello Clint,
      Bound actions are called in a bit different way, check following post – http://dotnet-posts.blogspot.com/2016/10/calling-dynamics-crm-2016-actions-using.html
      It’s weird that you can’t see it in metadata. I believe that issue was addressed already. What you can try – delete action and create it from scratch. Sometimes publishing happens immediately, sometimes it happens in hour or so. Anyway I believe you can reach Microsoft support and open a support ticket to get help.
      Thanks,
      Andrew

      1. Thanks for getting back to me. That blog contains pretty much the JavaScript I am using. I did find something very interesting though. I am so glad you suggested checking the metadata first. It definately was not showing up. I had tried republishing a few times. It never showed up. Then I created a Rollup field and published the solution (showing the customer how to replace a plugin left over from CRM2013). I rechecked the metadata today, and the Action is there. Strange, no?

        I have a theory: There needs to be some other customizations present besides the Action when you publish the solution for the Action to show up. Sounds like a bug, but this may be the workaround.

        I am still working through this as it’s now complaining “resource not found for the segment action_name”, but I know it’s there.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.