如何使用odata端点检索地址

问题描述 投票:0回答:1

我正在尝试检索标准实体上的地址。

请求如下:

https://mycrm.api.crm4.dynamics.com/api/data/v9.1/contacts(guid)

在这个例子中,我获得了所有字段,但我感兴趣的是address1_addressid,它似乎是一个Guid,引用了一些记录,但我在使用我检索的“多对一”关系列表中找不到它以下命令:

https://mycrm.api.crm4.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName='contact')?$select=LogicalName&$expand=ManyToOneRelationships($select=ReferencingAttribute,ReferencedEntity)

我想以通用的方式检索这些地址,因为我正在使用通用的NetStandard 2.0库。我将无法知道我将在哪个实体上工作,因此无法硬编码地址列表字段名称。

dynamics-crm odata dynamics-crm-365
1个回答
2
投票

以下是查找Contact to Address关系的一种方法:

https://myOrg.api.crm.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName='customeraddress')?$select=LogicalName&$expand=ManyToOneRelationships($select=ReferencingAttribute,ReferencedEntity)

AddressRelationship

我和https://myOrg.api.crm.dynamics.com/api/data/v9.1/contacts(guid)?$expand=address1_addressid有错。

我查看了MetaData并发现address1_addressid有一种主键: PrimaryKey

普通查找字段具有查找类型:Lookup

考虑到尝试扩展address1_addressid时出现的错误消息,我认为问题是address1_addressid的数据类型。

类型为“Microsoft.Dynamics.CRM.contact”的属性“address1_addressid”不是导航属性或复杂属性。只能扩展导航属性。

似乎不是使用$expand来获取地址详细信息,而是必须单独调用它: https://myOrg.api.crm.dynamics.com/api/data/v9.1/customeraddresses(guid)

UPDATE 通过查看完整的联系地址关系,通过此查询:https://myOrg.api.crm.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName='customeraddress')?$select=LogicalName&$expand=ManyToOneRelationships

我发现ReferencedEntityNavigationPropertyName被设置为Contact_CustomerAddress

fullRelationship

在谈到Navigation属性之前的错误消息,所以我试了一下。使用该属性命名允许我从联系人扩展地址信息:

https://myOrg.api.crm.dynamics.com/api/data/v9.1/contacts(guid)?$expand=Contact_CustomerAddress

有趣的是,扩展该导航属性将返回所有3个客户地址: Addresses

© www.soinside.com 2019 - 2024. All rights reserved.