Search code examples
phpapidynamics-crm

Microsoft Dynamics crm api-Create contact under account


Trying to create contact in Microsoft Dynamics crm using api.

The request url is https://alliedmodulartemp.api.crm.dynamics.com/api/data/v9.1/contacts

While creating contact want to set the contact under account (i.e) want to set _parentcustomerid_value.

Tried using the following formats:

URL:https://alliedmodulartemp.api.crm.dynamics.com/api/data/v9.1/contacts(POST)
input:
{
  "firstname":"alrinmyjammy",
 "emailaddress1":"leonmyjamkutty@gmail.com",
 "_parentcustomerid_value@odata.bind": "/accounts(a5f68843-ec4b-ea11-a812-000d3a579ca8)"

 }
input:
{
  "firstname":"alrinmyjammy",
 "emailaddress1":"leonmyjamkutty@gmail.com",
 "parentcustomerid@odata.bind": "/accounts(a5f68843-ec4b-ea11-a812-000d3a579ca8)"

 }

But the error is,

An error occurred while validating input parameters: Microsoft.OData.ODataException: A property '_parentcustomerid_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

  • Your body should be like below. I just tested with one of my CRM instance and worked fine for me. url is correct https://alliedmodulartemp.api.crm.dynamics.com/api/data/v9.1/contacts

    {
        "firstname": "Test 2 Postman",
        "lastname": "Test 2 Postman",
        "parentcustomerid_account@odata.bind":"/accounts(22B474B7-4F44-E111-8C06-1CC1DEE8BACD)"
    }