代码之家  ›  专栏  ›  技术社区  ›  Alex Gordon

如何通过web api执行crm book操作?

  •  1
  • Alex Gordon  · 技术社区  · 7 年前

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

    此Book操作的请求是什么样子的?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Arun Vinoth PrecogTechnologies    7 年前

    提到 MSDN 这个 BookRequest 消息预期 Appointment 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"
     }
    }