Associate primarycontactid to Case-Dynamics CRM web API -


i trying create case , associate contact in primarycontactid field. using alternate key contact below.

post https://xxxxx.crm.dynamics.com/api/data/v8.2/incidents http/1.1 accept: application/json odata-maxversion: 4.0 odata-version: 4.0 content-type: application/json; charset=utf-8 host: xxxxxx.crm.dynamics.com content-length: 161  {   "title": "case101",   "primarycontactid@odata.bind": "https://xxxxx.crm.dynamics.com/api/data/v8.2/contacts(xxi_xxx='2533274975913147')" } 

code below

using (httpclient httpclient = new httpclient())             {                 var method2 = new httpmethod("post");                 uri requesturi = new uri(string.format("{0}/api/data/v8.2/", url));                 httpclient.baseaddress = requesturi;                 httpclient.timeout = new timespan(0, 0, 4);  // 10 minutes                 httpclient.defaultrequestheaders.accept.clear();                 httpclient.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json"));                 result = gets2saccesstoken(url, pwd);                 httpclient.defaultrequestheaders.authorization = new authenticationheadervalue("bearer", result);                 httpclient.defaultrequestheaders.add("odata-maxversion", "4.0");                 httpclient.defaultrequestheaders.add("odata-version", "4.0");                 httprequestmessage request = new httprequestmessage(method,string.format( "contacts(xxxxx_xxxx='{0}')",xxxx.tostring()));                 request.content = new stringcontent(props.tostring(), encoding.utf8, "application/json");                 httprequestmessage request2 = new httprequestmessage(method2, string.format("incidents"));                 request2.content = new stringcontent(props1.tostring(), encoding.utf8, "application/json");                  httpresponsemessage createresponse1;                 createresponse1 = await httpclient.sendasync(request2);                 return createresponse1.content;          } 

however get:

an unexpected error occurred.","innererror":{ "message":"an unexpected error occurred.","type":"system.servicemodel.faultexception.","type":"system.servicemodel.faultexception1[[microsoft.xrm.sdk.organizationservicefault, microsoft.crm.extensibility.odata.crmodataservicedataprovider.createedmentity(crmodataexecutioncontext context, string edmentityname, edmentityobject entityobject, boolean isupsert)\r\n @ microsoft.xrm.sdk, version=8.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35]]","stacktrace":" @ microsoft.crm.extensibility.organizationsdkserviceinternal.create(entity entity, correlationtoken correlationtoken, callerorigintoken callerorigintoken, webservicetype servicetype, boolean checkadminmode, dictionary2 optionalparameters)\r\n @ microsoft.crm.extensibility.odata.crmodataexecutioncontext.create(entity entity)\r\n @ microsoft.crm.extensibility.odata.entitycontroller.postentityset(string entitysetname, edmentityobject entityobject)\r\

has experienced before?

you mixed up. verify & correct schema name.

incident has 2 optional contact lookups & schema name primarycontactid & responsiblecontactid.

primarycontactid@odata.bind 

but incident has mandatory customer lookup & schema name customerid. without incident cannot created. pass this, request succeed.

customerid@odata.bind 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -