繁体   English   中英

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

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

我正在尝试使用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;'));

它显示为“ code”:“”,“ message”:“您应指定上级联系人或帐户。” 我正在尝试使用导航属性。但是我找不到确切的property来发送customerId

我尝试使用以下链接: link1 link2 link3

我尝试了很长时间,实在太沮丧了。

在尝试@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")
        );

它显示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. 这个错误。

现在,我认为我们的要求是正确的,但格式不匹配。

最后的情况是使用以下请求在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';

我对PHP一无所知,除了很多人使用它。 您是否已签出Alexa CRM 他们有一个php工具包,可以简单地连接到CRM和PHP并与之交互。

在创建时关联实体

若要在创建新实体时将其与现有实体相关联,必须使用@odata.bind批注设置单值导航属性的值。

以下发布到帐户实体集的请求正文将创建一个与现有联系人关联的新帐户,其联系人ID值为00000000-0000-0000-0000-00000000000000001。

请求

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)"
}

响应

HTTP/1.1 204 No Content

OData-Version: 4.0

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

使用WebAPI创建实体-MSDN链接

暂无
暂无

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

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