[英]Creating Post with Dynamics CRM Web API
A Post entity ( https://msdn.microsoft.com/en-us/library/mt607553.aspx ) cannot be created using Dynamics CRM 2016 Online Web API.无法使用 Dynamics CRM 2016 Online Web API 创建 Post 实体 ( https://msdn.microsoft.com/en-us/library/mt607553.aspx )。
This payload should create a post on POST /api/data/v8.1/posts
此有效负载应在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) (来源 1 是自动发布,类型 7 是状态发布)
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).请注意, Post实体没有允许我设置相关实体(联系人、帐户、 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
例如,创建任务实体 ( https://msdn.microsoft.com/en-us/library/mt607619.aspx ) 在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 does not.在我看来,Post 应该公开类似regardingobjectid_contact_post@odata.bind
,但事实并非如此。
For context, this is how to create a Post via the SOAP endpoint and the SDK:对于上下文,这是通过 SOAP 端点和 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?有没有人有通过 Web API 创建的帖子的工作示例? Is this an omission in the Dynamics CRM Web API?这是Dynamics CRM Web API中的遗漏吗?
It doesn't look like this is listed in the limitations: https://msdn.microsoft.com/en-us/library/mt628816.aspx它看起来不像是在限制中列出的: 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.看起来 postregarding 实体是应该创建链接到联系人/帐户的地方。 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":
{
"regardingobjectid_contact@odata.bind":"/contacts(someguid)"
}
}
The response is回应是
Cannot create child entities before parent entity.不能在父实体之前创建子实体。
Nowhere it's mentioned like Post (activity feed) cannot be created using webapi.没有任何地方提到不能使用 webapi 创建帖子(活动提要)。 In fact it's not listed as crm webapi limitation like you pointed out.事实上,它并没有像您指出的那样列为 crm webapi 限制。
Also on comparison, _regardingobjectid_value
lookup property of post is different from activitypointer .同样在比较, _regardingobjectid_value
的查找财产后从不同activitypointer 。 Single valued navigation property too.单值导航属性也是。
Out of curiosity, My investigation moved towards the Partner - post_PostRegardings
出于好奇,我的调查转向了合作伙伴 - post_PostRegardings
Only thing making sense - postregarding
is strictly internal use.唯一有意义的事情 - postregarding
是严格的内部使用。 This could be the reason for all such behavior.这可能是所有此类行为的原因。 This is my theory per v8.2 today(Aug 12 2017)这是我今天的 v8.2 理论(2017 年 8 月 12 日)
Description : Represents which object an activity feed post is regarding.说明:表示活动提要帖子所涉及的对象。 For internal use only.仅供内部使用。
Entity Set path :[organization URI]/api/data/v8.2/postregardings实体集路径:[组织URI]/api/data/v8.2/postregardings
Base Type : crmbaseentity EntityType基本类型:crmbaseentity EntityType
Display Name : Post Regarding显示名称:发布相关信息
Primary Key : postregardingid主键:postregardingid
Ref: https://msdn.microsoft.com/en-us/library/mt608103.aspx参考: 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.看起来 MS 推荐社区使用组织服务来创建自定义发布记录。 Web api is still broken. Web api 仍然损坏。 Read more 阅读更多
I was recently struggling with this issue with an Activity table made using powerapps.我最近在使用 powerapps 制作的 Activity 表中努力解决这个问题。 For those who are interested, here's my post request:对于那些有兴趣的人,这是我的帖子请求:
POST: https://<MY_DOMAIN>.crm.dynamics.com/api/data/v9.1/<TABLE_NAME>
{
"regardingobjectid_contact@odata.bind": "/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但就目前而言,看起来 regardingobjectid 可能在 9.1 版中有效
using D365 Api v9.1使用 D365 Api v9.1
POST https://{domain}.crm4.dynamics.com/api/data/v9.1/posts
{
"regardingobjectid_contact@odata.bind":"/contacts(guid)",
"text": "This is a private message post",
"source": 1,
"type": 4
}
source:来源:
type:类型:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.