问题
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:
$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." Im trying to use navigation property.But I can't find the exact property
to send customerId
.
I have tried with following links: link1link2link3
I'm trying for a long time.It's too frustrated.
After I tried @Alex comment,I referred create incidents with following request,
$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.
this error.
Now I think our request is correct but format is mismatching.
回答1:
Finally case is create using below request in 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';
回答2:
I know nothing about PHP, except a lot of people use it. Have you checked out Alexa CRM? They have a php toolkit to simply connecting to, and interacting with CRM and PHP.
回答3:
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.
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.
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
来源:https://stackoverflow.com/questions/42501267/create-incident-in-dynamics-crm-using-api-in-php