通过API在Microsoft Dynamics CRM中为联系人实体创建注释 [英] Create annotation to a contact entity in Microsoft Dynamics CRM by API

本文介绍了通过API在Microsoft Dynamics CRM中为联系人实体创建注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与我通过API调用的Microsoft Dynamics CRM 2015有关.

This question is related to Microsoft Dynamics CRM 2015, that I'm calling through API.

我创建联系人实体:

POST [organization URI]/api/data/contacts
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "emailaddress1": "myemail@example.com",
}

登录面板后,它起作用了,我看到了新记录. 我可以通过API调用它:

It works, I see new record, after I log into the panel. And I can call it through the API:

[organization URI]/api/data/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)
{
  "@odata.context":"[organization URI]/api/data/$metadata#contacts/$entity",
  "@odata.etag":"W/\"460199\"",
  ...
  "contactid":"f76e4e7c-ea61-e511-80fd-3863bb342b00",
  "emailaddress1":"myemail@example.com",
  ....
}

我下一步要做的是添加与该联系人关联的注释记录. 遵循指南,我称之为:

Next thing I want to do, is to add annotation record associated with that contact. Following the guide I call:

POST [organization URI]/api/data/annotations
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "notetext": "TEST",
    'contact@odata.bind': 'contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)'
}

但是它返回400错误:

But it returns 400 error:

未声明的属性联系人",仅在有效负载中具有属性注释,而在有效负载中未找到属性值.在OData中,只有声明的导航属性和声明的命名流可以表示为没有值的属性.

An undeclared property 'contact' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.

当我打电话时:

POST [organization URI]/api/data/annotations
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "notetext": "TEST",
}

已创建新实体,但与联系人没有关系.

New entity is created, but without a relation to contact.

如何正确编写此POST请求?我在这里想念什么? 我怀疑contact@odata.bind应该以某种方式呈现,我尝试了contactid@odata.bindobject@odata.bindobjectid@odata.bind-但没有效果.

How to properly compose this POST request? What am I missing here? I suspect, that contact@odata.bind should be presented somehow different, I've tried contactid@odata.bind, object@odata.bind, objectid@odata.bind - but no effects.

有什么想法吗?

推荐答案

我发现此方法有效,但是有两个请求:

I've found this working, but in two requests:

POST [organization URI]/api/data/annotations
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "notetext": "TEST"
}

POST [organization URI]/api/data/contacts(f76e4e7c-ea61-e511-80fd-3863bb342b00)/Contact_Annotation/$ref
Content-Type: application/json; charset=utf-8
Accept: application/json
{
    "@odata.id": "[organization URI]/annotations(annotation_id_from_first_request)"
}

annotation_id_from_first_request值取自第一个请求的响应.

annotation_id_from_first_request value is taken form first request's response.

这篇关于通过API在Microsoft Dynamics CRM中为联系人实体创建注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆