Our use case is to create an entity and also link the navigation properties present in the entity. To achieve this use case we are making use of batch request with change set where the first request in the set will create the entity and subsequent requests will add the navigation property links to created entity.We are referring the created entity via $1 (Content -Id for first batch request) while creating request urls for adding navigation property links.
Our batch request looks like below:
--batch_B1 Content-Type: multipart/mixed;boundary=changeset_CS1 --changeset_CS1 Content-Type: application/http Content-Transfer-Encoding:binary Content-ID: 1 POST {{WebAPIUrl}}/contacts HTTP/1.1 Content-Type: application/json {"emailaddress3":"yahoo@gmail.com","lastname":"yahoo"} --changeset_CS1 Content-Type: application/http Content-Transfer-Encoding:binary Content-ID: 2 POST $1/opportunity_parent_contact/$ref HTTP/1.1 Content-Type: application/json {"@odata.id":"adobe3.api.crm.dynamics.com/.../opportunities(opportunityid=780e0283-5bf2-e311-945f-6c3be5a8dd64)"} --changeset_CS1-- --batch_B1--
In this we are creating an contact entity and then adding opportunity_parent_contact navigation property link. But i am getting below exception
{ "Message": "This operation is not supported for a relative URI.", "ExceptionMessage": "This operation is not supported for a relative URI.", "ExceptionType": "System.InvalidOperationException", "StackTrace": " at System.Uri.get_AbsoluteUri()\r\n at Microsoft.Crm.Extensibility.ODataV4.Edm.EdmExtensions.GetNormalizedRequestUri(HttpRequestMessage request)\r\n at Microsoft.Crm.Extensibility.CrmODataFormatter.GetPerRequestFormatterInstance(Type type, HttpRequestMessage request, MediaTypeHeaderValue mediaType)\r\n at System.Net.Http.Formatting.DefaultContentNegotiator.Negotiate(Type type, HttpRequestMessage request, IEnumerable`1 formatters)\r\n at System.Web.Http.Results.NegotiatedContentResult`1.Execute(HttpStatusCode statusCode, T content, IContentNegotiator contentNegotiator, HttpRequestMessage request, IEnumerable`1 formatters)\r\n at System.Net.Http.HttpRequestMessageExtensions.CreateResponse[T](HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration)\r\n at System.Net.Http.HttpRequestMessageExtensions.CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Func`2 errorCreator)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataExceptionHandler.CreateHttpErrorResponse(HttpRequestMessage request, Exception exception, HttpStatusCode statusCode, Int32 errorCode)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataExceptionHandler.CreateHttpErrorResponse(ExceptionHandlerContext context, HttpStatusCode statusCode, Int32 errorCode)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataExceptionHandler.Handle(ExceptionHandlerContext context)\r\n at System.Web.Http.ExceptionHandling.ExceptionHandler.HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)\r\n at System.Web.Http.ExceptionHandling.ExceptionHandler.System.Web.Http.ExceptionHandling.IExceptionHandler.HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)\r\n at System.Web.Http.ExceptionHandling.LastChanceExceptionHandler.HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)\r\n at System.Web.Http.ExceptionHandling.ExceptionHandlerExtensions.<HandleAsyncCore>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.Web.Http.HttpServer.<SendAsync>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.Web.OData.Batch.ODataBatchRequestItem.<SendMessageAsync>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.Web.OData.Batch.OperationRequestItem.<SendRequestAsync>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 Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ExecuteRequestMessagesAsyncImplementation>d__15.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 Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<>c__DisplayClass8_0.<<ExecuteRequestMessagesAsync>b__0>d.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 Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.<ExecuteAsync>d__11`1.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 Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.<ExecuteAsync>d__6`1.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 Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ExecuteRequestMessagesAsync>d__8.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.Web.OData.Batch.DefaultODataBatchHandler.<ProcessBatchAsync>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.Web.Http.Batch.HttpBatchHandler.<SendAsync>d__0.MoveNext()", "ErrorCode": "0x0" }
Can someone please help and let us know the cause of failure. Also any pointers for achieving the use case would be helpful.
Thanks