簡體   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