如何通过网络执行 crm 预订操作 api?

how to execute crm book action via web api?

CRM 公开 actions,它允许您通过 Web API 执行它们。

例如以下是 WinOpportunity 操作模式和 API:

<Action Name="WinOpportunity">
  <Parameter Name="OpportunityClose" Type="mscrm.opportunityclose" Nullable="false" />
  <Parameter Name="Status" Type="Edm.Int32" Nullable="false" />
</Action>

要执行这道题,您需要 POST 以下内容:

POST [Organization URI]/api/data/v8.2/WinOpportunity HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0

{
 "Status": 3,
 "OpportunityClose": {
  "subject": "Won Opportunity",
  "opportunityid@odata.bind": "[Organization URI]/api/data/v8.2/opportunities(b3828ac8-917a-e511-80d2-00155d2a68d2)"
 }
}

有没有办法执行 BookRequest 操作?

在检查 CSDL 架构时,我发现此操作定义为:

<Action Name="Book">
<Parameter Name="Target" Type="mscrm.crmbaseentity" Nullable="false"/>
<Parameter Name="ReturnNotifications" Type="Edm.Boolean"/>
<ReturnType Type="mscrm.BookResponse" Nullable="false"/>
</Action>

此图书操作的请求是什么样的?

同时引用 MSDN, the BookRequest message expects Appointment as Target. Book 操作。

// Create the ActivityParty instance.
ActivityParty party = new ActivityParty
{
    PartyId = new EntityReference(SystemUser.EntityLogicalName, userResponse.UserId)
};

// Create the appointment instance.
Appointment appointment = new Appointment
{
    Subject = "Test Appointment",
    Description = "Test Appointment created using the BookRequest Message.",
    ScheduledStart = DateTime.Now.AddHours(1),
    ScheduledEnd = DateTime.Now.AddHours(2),
    Location = "Office",
    RequiredAttendees = new ActivityParty[] { party },
    Organizer = new ActivityParty[] { party }                        
};                    

// Use the Book request message.
BookRequest book = new BookRequest
{
    Target = appointment
};

引用 MSDN,webapi 请求可能如下所示:(我正在使用现有的约会记录,仍然收到 400 错误请求)

POST [Organization URI]/api/data/v8.2/Book HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0

{
 "Target": {
  "activityid": "59ae8258-4878-e511-80d4-00155d2a68d1",
  "@odata.type": "Microsoft.Dynamics.CRM.appointment"
 }
}