The Post object ( https://msdn.microsoft.com/en-us/library/mt607553.aspx ) cannot be created using the Dynamics CRM 2016 online API.
This payload should create a post on POST /api/data/v8.1/posts
{ "text": "Test Single Post", "source": 1, "type": 7 }
(source 1 is an automatic post, type 7 is a status message)
But it returns:
{ "error": { "code":"", "message":"An unexpected error occurred.", "innererror" { "message":"An unexpected error occurred..." } } }
Sending the same payload only with "text" does not work either.
Note that the Post object does not have unambiguous navigation properties ( https://msdn.microsoft.com/en-us/library/mt607553.aspx#bkmk_SingleValuedNavigationProperties ), which will allow me to set up a related object (contact, account, etc. )
For example, creating a Task object ( https://msdn.microsoft.com/en-us/library/mt607619.aspx ) works fine on POST /api/data/v8.1/tasks
{ "subject": "Test Single Task", "description": "Test One Description of Task", " regardingobjectid_contact_task@odata.bind ": "/contacts(<someguid>)", "scheduledend": "2016-07-21T12:11:19.4875892Z" }
It seems to me that Post should expose something like regardingobjectid_contact_post@odata.bind , but it is not.
In context, this is how to create a message through the SOAP endpoint and SDK:
var result = Client.getOrganizationService().Create(new Post { Text = post.text, RegardingObjectId = new EntityReference( entityName, Guid.Parse(post.regarding_guid) ) });
Does anyone have a working example of Post created via web API? Is this an omission in the Dynamics CRM API?
It does not seem to be indicated in the restrictions: https://msdn.microsoft.com/en-us/library/mt628816.aspx
UPDATE
It looks like the postregarding object is where the link should be created for the contact / account. This can be demonstrated by requesting:
/posts?$filter=postregardingid/regardingobjectid_contact/contactid eq <someguid>
However, deep insertion, for example, does not work:
{ "text":"sometext", "postregardingid": { " regardingobjectid_contact@odata.bind ":"/contacts(someguid)" } }
Answer
Unable to create child entities in front of the parent.