在 php 中使用 api 在 dynamics crm 中创建事件
Create incident in dynamics crm using api in php
我正在尝试使用 php.For 在 Dynamics CRM 中创建案例,我可以看到标题、描述和客户是 required.So,我在下面的代码中尝试过:
$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;'));
它正在显示 "代码":"","消息":"您应该指定一个 parent 联系人或帐户。" 我正在尝试使用导航 property.But 我找不到要发送 customerId
的确切 property
。
我试了很久time.It太沮丧了。
在我尝试@Alex 评论后,我参考了 create incidents 以下请求,
$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.
这个错误。
现在我认为我们的请求是正确的,但格式不匹配。
我对PHP一无所知,除了很多人使用它。您检查过 Alexa CRM 了吗?他们有一个 php 工具包,可以简单地连接到 CRM 并与之交互 PHP。
在创建时关联实体
要在创建新实体时将它们关联到现有实体,您必须使用 @odata.bind
注释设置单值导航属性的值。
发布到帐户实体集的以下请求正文将创建一个与现有联系人关联的新帐户,其 contactid 值为 00000000-0000-0000-0000-000000000001。
请求
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)
最后在 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.For 在 Dynamics CRM 中创建案例,我可以看到标题、描述和客户是 required.So,我在下面的代码中尝试过:
$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;'));
它正在显示 "代码":"","消息":"您应该指定一个 parent 联系人或帐户。" 我正在尝试使用导航 property.But 我找不到要发送 customerId
的确切 property
。
我试了很久time.It太沮丧了。
在我尝试@Alex 评论后,我参考了 create incidents 以下请求,
$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.
这个错误。
现在我认为我们的请求是正确的,但格式不匹配。
我对PHP一无所知,除了很多人使用它。您检查过 Alexa CRM 了吗?他们有一个 php 工具包,可以简单地连接到 CRM 并与之交互 PHP。
在创建时关联实体
要在创建新实体时将它们关联到现有实体,您必须使用 @odata.bind
注释设置单值导航属性的值。
发布到帐户实体集的以下请求正文将创建一个与现有联系人关联的新帐户,其 contactid 值为 00000000-0000-0000-0000-000000000001。
请求
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)
最后在 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';