We are running into an error associating N:N entities via the Web API. Most of the related forum posts we have came across suggest inverting the entities, but we are getting an error regardless of which side we treat as the parent. To rule out a one-off error with this N:N relationship, we've also tried creating a new N:N relationship between the same two entities, but get the same corresponding errors. Below are sample Web API calls and returned errors, as well as a screenshot of the relationship. Any help would be appreciated.
Request 1:
POST https://{orgname}.crm.dynamics.com/api/data/v8.2/str_salesorders(3A79AAFD-1AB8-E611-80E8-FC15B428BC1C)/str_strsalesorder_systemuser/$ref HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0
{"@odata.id":"https://{orgname}.crm.dynamics.com/api/data/v8.2/systemusers(5C44C50A-5FAC-4150-8BDB-D1950A412438)"}
Response 1:
HTTP/1.1 500 Internal Server Error
OData-Version: 4.0
{
"error":{
"code":"","message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","innererror":{
"message":"propertyValue (System.Uri) should be EdmEntityObjectCollection","type":"Microsoft.Crm.CrmException","stacktrace":" at Microsoft.Crm.CrmException.Assert(Boolean condition, String message)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetNavigationPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, IEdmProperty edmProperty, EntityRelationship entityRelationship, Object propertyValue, Nullable`1 role)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.EdmTypeConverter.ConvertToCrmEntity(EdmEntityObject edmEntity, EntityReference entityReference)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceProperty(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String propertyName, Object edmPropertyValue)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceNavigationPropertyReference(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, CrmEdmEntityReference edmPropertyReference)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.UpdateNavigationRefInternal(String entityName, String key, String navigation, Uri link)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostNavigationRef(String entityName, String key, String navigation, Uri link)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
-----------
Request 2:
POST https://{orgname}.crm.dynamics.com/api/data/v8.2/systemusers(5C44C50A-5FAC-4150-8BDB-D1950A412438)/str_strsalesorder_systemuser/$ref HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0
{"@odata.id":"https://{orgname}.crm.dynamics.com/api/data/v8.2/str_salesorders(3A79AAFD-1AB8-E611-80E8-FC15B428BC1C)"}
Response 2:
HTTP/1.1 400 Bad Request
OData-Version: 4.0
{
"error":{
"code":"","message":"Invalid role specified for entity 'systemuser'in relationship 'str_strsalesorder_systemuser.Referencing'","innererror":{
"message":"Invalid role specified for entity 'systemuser'in relationship 'str_strsalesorder_systemuser.Referencing'","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":" at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Associate(EntityReference entityReference, Relationship relationship, EntityReferenceCollection relatedEntities, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Associate(EntityReference entityReference, Relationship relationship, EntityReferenceCollection relatedEntities)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateResourceNavigationPropertyReference(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, String navigationPropertyName, CrmEdmEntityReference edmPropertyReference)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.UpdateNavigationRefInternal(String entityName, String key, String navigation, Uri link)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostNavigationRef(String entityName, String key, String navigation, Uri link)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
*This post is locked for comments
I have the same question (0)

Report
All responses (
Answers (