简体   繁体   English

在PHP中使用API​​在Dynamics CRM中创建事件

[英]Create incident in dynamics crm using api in php

Im trying to create case in dynamics CRM using php.For that I can see that title,description and customer is required.So that I tried below code: 我正在尝试使用php在Dynamics CRM中创建案例。为此,我可以看到标题,描述和客户是必需的。因此我尝试了以下代码:

  $authHeader = 'Authorization:' . $type.' '.$access_token;
    //Request for incidents
  $data = array("title"=>"api_incident_title",
            "description" =>"api_incident_description",
    "primaryContactid" =>"https://vonageholdings.crm.dynamics.com/api/data/v8.0/accounts(ebaf25a6-f131-e611-80f8-c4346bac3990)"
        );
    //URL
    $url ='https://vonageholdings.crm.dynamics.com/api/data/v8.0/incidents';
    //request for incidents
    $data_string = json_encode($data);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array($authHeader,
            'Content-Type:application/json','Accept:application/json;'));

It's showing "code":"","message":"You should specify a parent contact or account." 它显示为“ code”:“”,“ message”:“您应指定上级联系人或帐户。” Im trying to use navigation property.But I can't find the exact property to send customerId . 我正在尝试使用导航属性。但是我找不到确切的property来发送customerId

I have tried with following links: link1 link2 link3 我尝试使用以下链接: link1 link2 link3

I'm trying for a long time.It's too frustrated. 我尝试了很长时间,实在太沮丧了。

After I tried @Alex comment,I referred create incidents with following request, 在尝试@Alex评论后,我通过以下请求提交了create events,

$data = array('primarycontactid@odata.bind' =>"https://xxxx.crm.dynamics.com/api/data/v8.0/contacts(4bafdfb0-08d7-e511-80eb-c4346bac3990)",
        'incident_customer_accounts'=>array("title"=>"case_account","description" =>"case")
        );

It shows A node of type 'StartObject' was read from the JSON reader when trying to read the contents of the navigation property 'incident_customer_accounts'; however, a 'StartArray' node was expected. 它显示A node of type 'StartObject' was read from the JSON reader when trying to read the contents of the navigation property 'incident_customer_accounts'; however, a 'StartArray' node was expected. A node of type 'StartObject' was read from the JSON reader when trying to read the contents of the navigation property 'incident_customer_accounts'; however, a 'StartArray' node was expected. this error. 这个错误。

Now I think our request is correct but format is mismatching. 现在,我认为我们的要求是正确的,但格式不匹配。

Finally case is create using below request in php 最后的情况是使用以下请求在php中创建

$data = array("title"=>"test",
        "description" =>"case",
        "customerid_contact@odata.bind" =>"/contacts(c18df8d6-74d9-e511-80eb-c4346bac3990)"
        );

 $url ='https://yyyyy.crm.dynamics.com/api/data/v8.0/incidents';

I know nothing about PHP, except a lot of people use it. 我对PHP一无所知,除了很多人使用它。 Have you checked out Alexa CRM ? 您是否已签出Alexa CRM They have a php toolkit to simply connecting to, and interacting with CRM and PHP. 他们有一个php工具包,可以简单地连接到CRM和PHP并与之交互。

Associate entities on create 在创建时关联实体

To associate new entities to existing entities when they are created you must set the value of single-valued navigation properties using the @odata.bind annotation. 若要在创建新实体时将其与现有实体相关联,必须使用@odata.bind批注设置单值导航属性的值。

The following request body posted to the accounts entity set will create a new account associated with an existing contact with the contactid value of 00000000-0000-0000-0000-000000000001. 以下发布到帐户实体集的请求正文将创建一个与现有联系人关联的新帐户,其联系人ID值为00000000-0000-0000-0000-00000000000000001。

Request 请求

POST [Organization URI]/api/data/v8.2/accounts HTTP/1.1

Content-Type: application/json; charset=utf-8

OData-MaxVersion: 4.0

OData-Version: 4.0

Accept: application/json

{
"name":"Sample Account",

"primarycontactid@odata.bind":"/contacts(00000000-0000-0000-0000-000000000001)"
}

Response 响应

HTTP/1.1 204 No Content

OData-Version: 4.0

OData-EntityId: [Organization URI]/api/data/v8.2/accounts(00000000-0000-0000-0000-000000000002)

Create an entity using WebAPI - MSDN link 使用WebAPI创建实体-MSDN链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM