web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : joU7eFufzXoYqGTYAnlusK
Power Automate - Building Flows
Unanswered

Calling msdyn_SearchResourceAvailability Dynamics WebAPI

Like (0) ShareShare
ReportReport
Posted on 12 May 2021 17:59:32 by 2

I'm building a series of flows to complete scheduling tasks using some custom entities and the Universal Resource Scheduling Resource Board. I've got quite far down the development path but I've hit a snag I could use some help with.

 

I'm trying to determine the next available time slot for a given bookable resource (or any bookable resource that fits requirements).

 

The msdyn_SearchResourceAvailability API looked like it was perfect for the job, and I followed the following links to get familiar with the API's requirements:

Search Resource Availability with Universal Resource Scheduling API - Microsoft Dynamics 365 Blog

How to use the Search Resource Availability API - Universal Resource Scheduling - Microsoft Dynamics 365 Blog

 

I've not called an API before, so Joshua's post was fantastic at getting me authenticated so I could make my API calls from a HTTP POST:

Dynamics 365 WebAPI calls and Flow (dynamicconsultantsgroup.com)

 

I've then used a Compose and Parse JSON to provide some inputs I intend to make dynamic in the near future. I've dug around the internet for relevant JSON calls for this API, but it seems no matter what I do, the API doesn't like it. I'm no longer certain I'm even calling the API correctly.

 

Here's an example input (though I've tried referencing a resource requirement GUID and many other variations of the 3 mandatory inputs):

Screenshot 2021-05-13 032648 - Compose.png

 

This then fed into the Parse JSON action:

Screenshot 2021-05-13 032744 - Parse JSON.png

 

I then request authorisation to get an access token using Joshua's method:

Screenshot 2021-05-13 033140 - RequestOAuth2Token.png

 

I finally feed all this in to the WebAPI call:

Screenshot 2021-05-13 033257 - CallWebAPI.png

 

So far I can't get past the following error:

 

An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.
 at System.Web.OData.Formatter.Deserialization.DeserializationHelpers.ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, Object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
 at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
 at Microsoft.Crm.Extensibility.CrmODataEntityDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
 at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ReadResource(ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
 at Microsoft.Crm.Extensibility.ODataV4.CrmODataActionPayloadDeserializer.ReadEntry(ODataDeserializerContext readContext, ODataParameterReader reader, IEdmOperationParameter parameter)
 at Microsoft.Crm.Extensibility.ODataV4.CrmODataActionPayloadDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
 at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)

 

 

I've tried formatting the input for the API in as many ways I can think of while keeping it simple, I've tried to amend the JSON schema based on OData types, I've tried to switch data types in the original Compose and I've tried amending the URI of the WebAPI call just in case, but the above error is the furthest I've gotten. 

 

The appear to be a decent amount of people who've got this API working as a call from a program in C# but I can't seem to find an example of anyone getting this working in Microsoft Flow. Am I just doing something obviously wrong?

 

Thanks!

I have the same question (0)
  • rrovira Profile Picture
    Microsoft Employee on 14 May 2021 at 18:45:07
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    Hello, @JoeBond!

     

    While doing some research I found out that most users have encounter this error due to field not being recognized or perhaps a wrong format. I've been looking at the "msdyn_fromdate" to "msdyn_todate" and I believe they require a DateTime so perhaps you could try checking the format of both of them to make sure that's not the issue. I'll keep on researching to see if something else pops up! 

     

    Cheers,

    Rodrigo

  • JoeBond Profile Picture
    2 on 16 May 2021 at 13:24:36
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    Hey @rrovira,

     

    Thanks for giving this a crack for me.

     

    I've tried this as many ways as I can think of - even removing dates and cutting back the code as far as possible by just providing a Resource Requirement id reference (as below) has the same issue:

    {
     "Version": "1",
     "Requirement": {
     "msdyn_resourcerequirementid": "7abb7dab-37b3-eb11-8236-00224814ba40"
     },
     "Settings": {}
    }

     

    So how are supposed to define a type within the http request?

     

    I've tried the below two versions with no success:

    "msdyn_fromdate": {
    "odata.type": "Edm.DateTimeOffset",
    "value": "@{utcNow()}"
    },

     

    "msdyn_fromdate":{
    "@{string('@odata.type')}": "Edm.DateTimeOffset",
    "value": "@{utcNow()}"
    },

     

    I feel like I'm so close but I'm clearly missing something fundamental and there are so few examples available online that I can't work out what the missing piece is.

  • alexarg Profile Picture
    Microsoft Employee on 21 Jul 2021 at 19:54:31
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    @JoeBond this functionality has been corrected and enabled. You should now be able to call msdyn_SearchResourceAvailability via Web API. To do that, make sure:

    1. Vesrion 3 is being used 
    2. “IsWebApi”: true is specified
    3. Proper “@odata.type” annotations for nested objects are provided

     

    Sample:

    {

        "Version": "3",

        "IsWebApi": true,

        "Requirement": {

            "msdyn_fromdate": "2021-07-14T00:00:00Z",

            "msdyn_todate": "2021-07-15T23:59:00Z",

            "msdyn_remainingduration": 60,

            "msdyn_duration": 60,

            "@odata.type": "Microsoft.Dynamics.CRM.msdyn_resourcerequirement"

        },

        "Settings": {

            "ConsiderSlotsWithProposedBookings": false,

            "MovePastStartDateToCurrentDate": true,

            "@odata.type": "Microsoft.Dynamics.CRM.expando"

        },

        "ResourceSpecification": {

            "@odata.type": "Microsoft.Dynamics.CRM.expando",

            "ResourceTypes@odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",

            "ResourceTypes": [

                {

                    "@odata.type": "Microsoft.Dynamics.CRM.expando",

                    "value": "1"

                },

                {

                    "@odata.type": "Microsoft.Dynamics.CRM.expando",

                    "value": "2"

                }

            ]

        }

    }

     

    Hope this helps.

  • TD2021 Profile Picture
    5 on 29 Jul 2021 at 16:25:36
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    This works, thanks 

  • HectorMeneses Profile Picture
    2 on 05 Jan 2022 at 20:30:40
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    @alexarg ,

     

    I wonder if you could help me figure out how to add Contraints to msdyn_SearchResrouceAvailability

    So far I have tried the following:

    • Setting roleid
      "Constraints@odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",
      "Constraints": [
      {
      "Roles@odata.type":"Collection(Microsoft.Dynamics.CRM.role)",
      "Roles": [
      {
      "roleid": "0fe3e6d0-ac35-ec11-b6e6-002248091eec"
      }
      ]
      }
      ]
      In this case I get the following error:
      "message": "An error occurred while validating input parameters: System.ArgumentNullException: Value cannot be null.\r\n at System.RuntimeType.MakeGenericType....

    •  
    • Setting as expando
      "Constraints": {
      "@odata.type": "Microsoft.Dynamics.CRM.expando",
      "Roles@odata.type": "Collection(Microsoft.Dynamics.CRM.expando)",
      "Roles":[
      {
      "@odata.type": "Microsoft.Dynamics.CRM.expando",
      "value": "0fe3e6d0-ac35-ec11-b6e6-002248091eec"
      }
      ]
      }
      In this case I get no results:
      {
      "@odata.context": "https://{site}.crm.dynamics.com/api/data/v9.0/$metadata#Microsoft.Dynamics.CRM.msdyn_SearchResourceAvailabilityResponse",
      "TimeSlots": [],
      "Resources": [],....

    • Setting as a saved Resource Requirement that contains the role I would like to filter with
      "Requirement": {
      "msdyn_resourcerequirementid": "ebf79b73-d06c-ec11-8943-000d3a314d4a",
      "@odata.type": "Microsoft.Dynamics.CRM.msdyn_resourcerequirement"
      }
      In this case I get results but they are not filtered correctly.

    Thanks for your help!

  • Frozen Profile Picture
    on 30 Apr 2022 at 18:09:42
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    @alexarg I am also struggling with applying filters - would love to see a working example of:

    - using an existing Resource Requirement record

    - setting skills/Characteristics in the Constraint entity

     

    Thanks in advance!

     

  • Siva Tanguturi Profile Picture
    6 on 13 Jul 2022 at 20:00:59
    Re: Calling msdyn_SearchResourceAvailability Dynamics WebAPI

    How can we specify msdyn_timegroup (Fulfillment preference) with this input? Tried like below but getting exception "

    An error occurred while validating input parameters: Microsoft.OData.ODataException: Cannot find nested property 'msdyn_timegroup' on the resource type 'Microsoft.Dynamics.CRM.msdyn_resourcerequirement'.

    "

     

    {

        "Version""3",
        "IsWebApi"true,
        "Requirement": {
            "msdyn_fromdate""2022-07-14T00:00:00Z",
            "msdyn_todate""2022-07-15T23:59:00Z",
            "msdyn_duration"120,
            "msdyn_remainingduration"120,
            "@odata.type""Microsoft.Dynamics.CRM.msdyn_resourcerequirement",
            "msdyn_timegroup":
            {
                "@odata.type""Microsoft.Dynamics.CRM.msdyn_timegroup",
                "Id""3f2f41ec-3d02-ed11-82e4-00224806c5e8",
                "LogicalName""msdyn_timegroup",
                "Name""Appointment Duration",
                "KeyAttributes": [],
                "RowVersion""8461324"
            }
        },
        
           

        "Settings": {
            "ConsiderSlotsWithProposedBookings"true,
            "ConsiderTravelTime"true,
            "ConsiderSlotsWithOverlappingBooking"false,
            "ConsiderSlotsWithLessThanRequiredDuration":false,
            "MovePastStartDateToCurrentDate"true,
            "@odata.type""Microsoft.Dynamics.CRM.expando"
        },

        "ResourceSpecification": {
            "@odata.type""Microsoft.Dynamics.CRM.expando",
           "ResourceTypes@odata.type""Collection(Microsoft.Dynamics.CRM.expando)",
            "ResourceTypes": [
                {
                    "@odata.type""Microsoft.Dynamics.CRM.expando",
                    "value""2"
                }

            ]

        }

    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 788 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 452 Moderator

#3
developerAJ Profile Picture

developerAJ 302

Last 30 days Overall leaderboard