Creating Post with Dynamics CRM Web API
Asked Answered
F

3

7

A Post entity (https://msdn.microsoft.com/en-us/library/mt607553.aspx) cannot be created using Dynamics CRM 2016 Online Web 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 auto post, type 7 is a status post)

But it returns:

{
    "error":
    {
        "code":"",
        "message":"An unexpected error occurred.",
        "innererror"
        {
            "message":"An unexpected error occurred..."
        }
    }
}

Submitting the same payload with only "text" fails too.

Notice that the Post entity does not have single-valued navigation properties (https://msdn.microsoft.com/en-us/library/mt607553.aspx#bkmk_SingleValuedNavigationProperties) that will allow me to set the related entity (contact, account, etc).

For example, Creating a Task entity (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",
    "[email protected]": "/contacts(<someguid>)",
    "scheduledend": "2016-07-21T12:11:19.4875892Z"
}

It seems to me that Post should expose something like [email protected], but it does not.

For context, this is how to create a Post via the SOAP endpoint and the 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 a Post created via the Web API? Is this an omission in the Dynamics CRM Web API?

It doesn't look like this is listed in the limitations: https://msdn.microsoft.com/en-us/library/mt628816.aspx

UPDATE

It appears that the postregarding entity is where the link should be created to contact/account. This can be demonstrated by querying:

/posts?$filter=postregardingid/regardingobjectid_contact/contactid eq <someguid>

However, a "deep insert" like so does not work:

{
    "text":"sometext",
    "postregardingid": 
         {
             "[email protected]":"/contacts(someguid)"
         }
}

The response is

Cannot create child entities before parent entity.

Ferrous answered 20/7, 2016 at 17:33 Comment(0)
Q
0

Nowhere it's mentioned like Post (activity feed) cannot be created using webapi. In fact it's not listed as crm webapi limitation like you pointed out.

Also on comparison, _regardingobjectid_value lookup property of post is different from activitypointer. Single valued navigation property too.

Out of curiosity, My investigation moved towards the Partner - post_PostRegardings

Only thing making sense - postregarding is strictly internal use. This could be the reason for all such behavior. This is my theory per v8.2 today(Aug 12 2017)

Description: Represents which object an activity feed post is regarding. For internal use only.
Entity Set path:[organization URI]/api/data/v8.2/postregardings
Base Type: crmbaseentity EntityType
Display Name: Post Regarding
Primary Key: postregardingid

Ref: https://msdn.microsoft.com/en-us/library/mt608103.aspx

Update:

Looks like MS recommend the community to use Organization service to create a custom Post record. Web api is still broken. Read more

Qualifier answered 12/8, 2017 at 23:26 Comment(0)
B
0

I was recently struggling with this issue with an Activity table made using powerapps. For those who are interested, here's my post request:

POST: https://<MY_DOMAIN>.crm.dynamics.com/api/data/v9.1/<TABLE_NAME>
{
    "[email protected]": "/contacts(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)",
    "description": "data for this entity",
    "subject": "more data"
}

I didn't do anything different from other peoples' answers. I'll give an update if this problem fails sporadically. But as it is right now, it looks like regardingobjectid may be working in version 9.1

Bedizen answered 31/3, 2022 at 15:47 Comment(0)
S
0

using D365 Api v9.1

POST https://{domain}.crm4.dynamics.com/api/data/v9.1/posts
{
  "[email protected]":"/contacts(guid)",
  "text": "This is a private message post",
  "source": 1,
  "type": 4
}

source :

  1. Auto Post
  2. Manual Post
  3. ActionHub Post

type :

  1. Check-in
  2. Idea
  3. News
  4. Private Message
  5. Question
  6. Re-Post
  7. Status

App result

Shelton answered 25/11, 2022 at 7:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.