“Undeclared Property Error” in assigning lookup field when using web API Dynamics 365

I was trying to use the Xrm.WebApi.createRecord d365 API to create a record but was getting the error :

“An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property ‘YOUR FIELD’ which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.”

This error seems to be a common error and the solution could be found everywhere online but in my case, the solutions like this still could not resolve the issue. After much debugging and trying several things, the solution below worked for me:

I changed my code from this :

Xrm.WebApi.createRecord("vic_stageduration", { "subject": "Resumed from Paused", "RegardingObjectId@odata.bind": "/vic_applications(ee146fb0-f36a-4577-9589-9704ee3804f4)", "actualstart": new Date() }).then(...........

to this:

Xrm.WebApi.createRecord("vic_stageduration", { "subject": "Resumed from Paused", "regardingobjectid_vic_application_vic_stageduration@odata.bind": "/vic_applications(ee146fb0-f36a-4577-9589-9704ee3804f4)", "actualstart": new Date() }).then(.........

I cannot say if this was caused by an API modification on Microsoft’s side, I hope the solution here helps a junior developer somewhere, errors like this could easily be a nightmare for an inexperienced developer.