how to get resource's availability using web api?
Asked Answered
I

1

6

CRM 2016 exposes odata/web api, and has functions and actions out of the box.

With the organization service, we can issue a request like this:

// Create the van required resource object.
RequiredResource vanReq = new RequiredResource
{
    ResourceId = _vanId,
    ResourceSpecId = _specId
};

// Create the appointment request.
AppointmentRequest appointmentReq = new AppointmentRequest
{
    RequiredResources = new RequiredResource[] { vanReq },
    Direction = SearchDirection.Backward,
    Duration = 60,
    NumberOfResults = 10,
    ServiceId = _plumberServiceId,
    // The search window describes the time when the resouce can be scheduled.
    // It must be set.
    SearchWindowStart = DateTime.Now.ToUniversalTime(),
    SearchWindowEnd = DateTime.Now.AddDays(7).ToUniversalTime(),
    UserTimeZoneCode = 1
};

// Verify whether there are openings available to schedule the appointment using this resource              
SearchRequest search = new SearchRequest
{
    AppointmentRequest = appointmentReq
};
SearchResponse searched = (SearchResponse)_serviceProxy.Execute(search);

if (searched.SearchResults.Proposals.Length > 0)
{
    Console.WriteLine("Openings are available to schedule the resource.");
}

Is it possible to mimic this functionality using functions/action or any other odata functionality?

I believe that the request should be something like this:

crmOrg/api/v8.1/Search(AppointmentRequest=@request)?@request=

However, I'm not sure how to encode the rest of the request.

Ixion answered 3/10, 2017 at 19:7 Comment(2)
_serviceProxy.Execute will send a request over http (tcp port 80) to the end point (using HTTP GET). You can capture this request on your PC with either a network sniffer or with a debugging tool. I prefer Fiddler, you can configure this to be a proxy between your app and the end point and it will capture traffic. Then it is just a matter of reading the URL for each specific request you want to mimic. So create request in c# and capture generated URL in Fiddler (also it is a free tool, I have no affiliation with telerik).Larimor
Probably you can compose the fetchxml & issue a web api call like this: community.dynamics.com/crm/b/mscrmcustomization/archive/2016/11/…Wouldbe
M
3

The parameter goes like:

http://yourcrm.org/org/api/data/v8.1/Search(AppointmentRequest=@ar)/?@ar={SearchWindowStart:%272017-01-01%27,Duration:60,NumberOfResults:10}

it is url encoded json of serialized AppointmentRequest class.

{
  SearchWindowStart:'2017-01-01',
  Duration: 60,
  NumberOfResults:10,
  etc...
}

More info here: https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.appointmentrequest.aspx

ODATA reference: http://odata.github.io/WebApi/04-06-function-parameter-support/

Macmillan answered 11/10, 2017 at 11:43 Comment(1)
Reference docs for this particular API are here: learn.microsoft.com/en-us/dynamics365/customer-engagement/…Tameshatamez

© 2022 - 2024 — McMap. All rights reserved.