Hi Friends,
I am getting 400 bad request while try to create product and salesorders. The following json format i am sending to create product and salesorders.
For Product:
Url is: insyncdev.api.crm8.dynamics.com/.../products
Content Type : application/json
Authorization: Bearer {Token}
Body:
{
"statecode": 0,
"productid": "69bdc695-9b05-e811-a958-000d3af28edd",
"iskit": false,
"description": "Soft and sweet",
"productnumber": "I02",
"msdyn_taxable": true,
"producttypecode": 1,
"name": "BMW",
"isstockitem": false,
"msdyn_converttocustomerasset": false,
"productstructure": 1,
"_defaultuomscheduleid_value": "5ef8c035-52fd-4ba5-897c-9780c16c8f39",
"versionnumber": 1363537,
"exchangerate": 1,
"statuscode": 1,
"quantitydecimal": 0,
"msdyn_purchasename": "BMW",
"_modifiedonbehalfby_value": null,
"producturl": null,
"vendorname": null,
"vendorid": null,
"validfromdate": null,
"traversedpath": null,
"price_base": null,
"standardcost": null,
"_createdonbehalfby_value": null,
"entityimage_timestamp": null,
"_msdyn_defaultvendor_value": null,
"vendorpartnumber": null,
"currentcost": null,
"_modifiedbyexternalparty_value": null,
"price": null,
"hierarchypath": null,
"suppliername": null,
"entityimage_url": null,
"msdyn_upccode": null,
"overriddencreatedon": null,
"utcconversiontimezonecode": null,
"stageid": null,
"_msdyn_transactioncategory_value": null,
"dmtimportstate": null,
"_createdbyexternalparty_value": null,
"standardcost_base": null,
"stockvolume": null,
"_parentproductid_value": null,
"entityimage": null,
"processid": null,
"msdyn_fieldserviceproducttype": null,
"timezoneruleversionnumber": null,
"importsequencenumber": null,
"currentcost_base": null,
"validtodate": null,
"stockweight": null,
"entityimageid": null,
"quantityonhand": null,
"size": null
}
Response:
{
"error": {
"code": "0x0",
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"innererror": {
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.TypeConverters.EntityReferenceAttributeTypeConverter.ConvertToCrmTypeInternal(Guid edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetStructuralPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, String crmAttributeName, IEdmProperty edmProperty, Object propertyValue)\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.CreateEdmEntity(CrmODataExecutionContext context, String edmEntityName, EdmEntityObject entityObject, Boolean isUpsert)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySetInternal(CrmODataExecutionContext context, String edmEntityName, EdmEntityObject entityObject, Boolean isUpsert)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySet(String entitySetName, EdmEntityObject entityObject)\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.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.ValidateEnd(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.ValidateEnd(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.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
* What does it mean by navigation property and how to do it?
For SalesOrders:
Url is: insyncdev.api.crm8.dynamics.com/.../salesorders
Content Type : application/json
Authorization: Bearer {Token}
Body:
{
"statecode": 0,
"msdyn_totalchargeablecostrollup_base": 0,
"statuscode": 1,
"msdyn_ordertype": 192350000,
"msdyn_totalnonchargeablecostrollup_state": 1,
"msdyn_psastate": 192350000,
"ordernumber": "ORD-01000-W7K1Q6",
"pricingerrorcode": 0,
"msdyn_totalnonchargeablecostrollup_base": 0,
"msdyn_totalchargeablecostrollup": 0,
"_ownerid_value": "dfa1495d-9f01-e811-a958-000d3af289b8",
"shipto_freighttermscode": 1,
"name": "Laptop",
"discountpercentage": 25,
"versionnumber": 1364305,
"totalamountlessfreight": 187.5,
"freightamount": 30,
"prioritycode": 1,
"ispricelocked": false,
"_transactioncurrencyid_value": "dd0230a0-16ec-e711-a97b-000d3af26964",
"exchangerate": 1,
"totaldiscountamount": 62.5,
"totallineitemamount_base": 250,
"totalamount": 217.5,
"totallineitemamount": 250,
"msdyn_totalchargeablecostrollup_state": 1,
"totaltax": 0,
"totaldiscountamount_base": 62.5,
"msdyn_psastatusreason": 192350000,
"totallineitemdiscountamount": 0,
"totallineitemdiscountamount_base": 0,
"msdyn_totalnonchargeablecostrollup": 0,
"totalamount_base": 217.5,
"_customerid_value": "2e593c87-3107-e811-a956-000d3af28a0d",
"willcall": false,
"freightamount_base": 30,
"totaltax_base": 0,
"totalamountlessfreight_base": 187.5,
"_campaignid_value": null,
"shipto_line3": null,
"shipto_name": null,
"importsequencenumber": null,
"discountamount": null,
"shipto_stateorprovince": null,
"_slaid_value": null,
"_quoteid_value": null,
"billto_composite": null,
"onholdtime": null,
"processid": null,
"shipto_postalcode": null,
"billto_line3": null,
"billto_stateorprovince": null,
"stageid": null,
"billto_telephone": null,
"shipto_line2": null,
"shipto_contactname": null,
"shipto_fax": null,
"entityimage_url": null,
"description": null,
"overriddencreatedon": null,
"paymenttermscode": null,
"shipto_telephone": null,
"_msdyn_accountmanagerid_value": null,
"_opportunityid_value": null,
"timezoneruleversionnumber": null,
"billto_name": null,
"shipto_country": null,
"_contactid_value": null,
"shippingmethodcode": null,
"billto_addressid": null,
"lastonholdtime": null,
"_modifiedonbehalfby_value": null,
"_accountid_value": null,
"traversedpath": null,
"_slainvokedid_value": null,
"shipto_composite": null,
"billto_line2": null,
"discountamount_base": null,
"shipto_addressid": null,
"billto_postalcode": null,
"billto_fax": null,
"_msdyn_contractorganizationalunitid_value": null,
"billto_city": null,
"lastbackofficesubmit": null,
"freighttermscode": null,
"emailaddress": null,
"_owningteam_value": null,
"datefulfilled": null,
"_msdyn_account_value": null,
"billto_country": null,
"_createdonbehalfby_value": null,
"billto_contactname": null,
"utcconversiontimezonecode": null,
"submitstatus": null,
"submitstatusdescription": null,
"shipto_city": null,
"shipto_line1": null,
"submitdate": null,
"entityimage_timestamp": null,
"requestdeliveryby": null,
"entityimage": null,
"billto_line1": null,
"entityimageid": null
}
Response:
{
"error": {
"code": "0x0",
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"innererror": {
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.TypeConverters.EntityReferenceAttributeTypeConverter.ConvertToCrmTypeInternal(Guid edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetStructuralPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, String crmAttributeName, IEdmProperty edmProperty, Object propertyValue)\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.CreateEdmEntity(CrmODataExecutionContext context, String edmEntityName, EdmEntityObject entityObject, Boolean isUpsert)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySetInternal(CrmODataExecutionContext context, String edmEntityName, EdmEntityObject entityObject, Boolean isUpsert)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PostEntitySet(String entitySetName, EdmEntityObject entityObject)\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.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.ValidateEnd(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.ValidateEnd(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.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
I am middle of my project and it is urgent to get the solution for it. Please send the body part to create the product or the procedure to create the product using Web Api.
*This post is locked for comments