Troubleshooting Tips – Create records in Dynamics 365 CE using Postman

By | February 6, 2020
Rate this post

Prerequisites
The article is targetted to audience with working experience in

  • Dynamics CE/CE SDK
  • Postman + OAUTH

This is fairly simple and everyone knows how to create records in Dynamics 365 CE. I will not cover the scenario on authentication .

Scenario

Create a feedback record in CRM with association to knowledge article

JSON Payload

{
    "comments": "I love this work",
    "title": "I love this work",
    "regardingobjectid_knowledgearticle@odata.bind": "knowledgearticles(D9C88EDC-3439-EA11-80FD-000D3AF8B049)",
    "rating": "100",
    "minrating": "0",
    "maxrating": "100"
}

If you notice here I have set regarding to knowledge article entity and specified a valid KnowledgeArticleId. What do you expect to happen? Will it work? Technically it but this particular scenario fails to work. Why? What’s the error?

Error

{
  "error": {
    "code": "",
    "message": "An undeclared property 'regardingobject_knowledgearticle' 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.",
    "innererror": {
      "message": "An undeclared property 'regardingobject_knowledgearticle' 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.",
      "type": "Microsoft.Crm.CrmHttpException",
      "stacktrace": "   at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ValidateInputParameters(ModelStateDictionary controllerModelState)\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.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.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.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
  }
}

Does it make sense? This is generic ODATA error which means that the payload you’ve provided is not correct.

It is very easy to fall into this trap because we most often assume that schema name for any lookup field ex: regardingobjectid must the relationship name as shown in CRM. By and large that’s true that’s why I chose regardingobjctid_knowledgearticle. But in this scenario this is obviously not correct.

Troubleshooting

When you begin troubleshooting you start looking at the metadata (usually in CRM UI), we go through the list of fields and most of the time that does the trick. I did the same and yet this did not work.

Eventually I browsed the metadata and voilĂ !! Found my culprit. The schema name was different.

Metadata example

We should look at the value of ReferencedProperty. Which is the correct field name. See below

<NavigationProperty Name="KnowledgeArticleId" Type="mscrm.knowledgearticle" Nullable="false" Partner="KnowledgeArticle_Feedback">
    <ReferentialConstraint Property="_regardingobjectid_value" ReferencedProperty="knowledgearticleid"/>
</NavigationProperty>

So the correct name is KnowledgeArticleId@odata.bind and using that everything worked fine.

How do you browse metadata? http://yourorg/api/data/v9.1/$metadata. Please understand that there are performance implications for using this. Please do not do this often. I did that and kept a copy of it. Yes the data changes but can always do that periodically.

Hope you enjoyed reading this little tip!