cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoeBond
Frequent Visitor

Calling msdyn_SearchResourceAvailability Dynamics WebAPI

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

 

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!

4 REPLIES 4
rrovira
Microsoft
Microsoft

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
Frequent Visitor

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
Microsoft
Microsoft

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

This works, thanks 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Users online (897)