Search code examples
dynamics-crmmicrosoft-dynamicsoffice365apidynamics-crm-365

Dynamics - Creating a Task using API


    {Method: POST, RequestUri: 'https://cmpanydynamicsurl.com/api/data/v8.2/tasks', Version: 1.1, Content: System.Net.Http.StringContent, 
     Headers:
      {
        OData-MaxVersion: 4.0
        OData-Version: 4.0
        Accept: application/json
        Content-Type: application/json; charset=utf-8
        Content-Length: 162
      }}

Using the above request, I am trying to create a task against an account using Dynamics API post action.

Json Model being sent -

 {
    "subject":"NEW TEST TASK FOR ACCOUNT",
    "[email protected]":"/accounts(08b582ad-4e2f-e711-8101-5065f38a4a21)"
 }

I am receiving this error message and have had no luck with searching the internet?

A property '_regardingobjectid_value' which only has property annotations in the payload but no property value is declared to be of type 'Edm.Guid'. In OData, only navigation properties and named streams can be represented as properties without values.


Solution

  • The correct payload is

    {
        "subject": "NEW TEST TASK FOR ACCOUNT",
        "[email protected]": "/accounts(08b582ad-4e2f-e711-8101-5065f38a4a21)"
    }
    

    You have to tell somehow to which object type you are binding, because regardingobjectid has mutliple types, and every type has its own separate relationship (in this case regardingobjectid_account). You are trying to bind value to a plain "Guid" property (because "_regardingobjectid_value" is a "Guid") but such property should be assigned exactly the same as you are doing with subject, so simply "_regardingobjectid_value": "08b582ad-4e2f-e711-8101-5065f38a4a21" but this will not work as you did not provide the type of entity.