dynamics-crm - Dynamics365 web api 更新与 upsert

标签 dynamics-crm microsoft-dynamics-webapi

我很困惑。我理解这两者之间的实际区别,但我看不出这里的实际实现有任何区别。

这是文档的摘录

Basic update

Update operations use the HTTP PATCH verb. Pass a JSON object containing the properties you want to update to the URI that represents the entity. A response with a status of 204 will be returned if the update is successful.

This example updates an existing account record with the accountid value of 00000000-0000-0000-0000-000000000001.

PATCH [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001) HTTP/1.1  
Content-Type: application/json  
OData-MaxVersion: 4.0  
OData-Version: 4.0  

{  
    "name": "Updated Sample Account ",  
    "creditonhold": true,  
    "address1_latitude": 47.639583,  
    "description": "This is the updated description of the sample account",  
    "revenue": 6000000,  
    "accountcategorycode": 2  
}


Upsert

An upsert operation is exactly like an update. It uses a PATCH request and uses a URI to reference a specific entity. The difference is that if the entity doesn’t exist it will be created. If it already exists, it will be updated. Normally when creating a new entity you will let the system assign a unique identifier. This is a best practice. But if you need to create a record with a specific id value, an upsert operation provides a way to do this. This can be valuable in situation where you are synchronizing data in different systems.

Sometimes there are situations where you want to perform an upsert, but you want to prevent one of the potential default actions: either create or update. You can accomplish this through the addition of If-Match or If-None-Match headers. For more information, see Limit upsert operations.



所以实际上Basic update如上所述将是 upsert并实现真正的基本更新(如果给定帐户存在则更新,否则为 404)我需要添加 If-Match: *标题到 PATCH要求。

我理解正确吗?

最佳答案

我在这里和你有同样的理解。在实践中,我发现使用没有 If-Match: * 的补丁请求如果记录不存在,将进行插入。然而,令人费解的是,当 upsert 成功插入一条记录时,它返回一个 404错误。当我包含 If-Match: * , 我收到了 400更新失败时出错。

关于dynamics-crm - Dynamics365 web api 更新与 upsert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48683975/

相关文章:

javascript - 无法通过 Web API 客户端关闭事件

javascript - 获取子数据 Microsoft Dynamics WebAPI

odata - 通过API为Microsoft Dynamics CRM中的联系人实体创建注释

javascript - Typescript 模块导入的相对路径指向错误的目录

javascript - 如何获取选定的 View ?

javascript - Xrm.Page 对象层次结构

javascript - 覆盖自定义事件的“标记完成”功能区按钮

dynamics-crm-2011 - 如何在 MS Dynamics CRM 2011 中导出审计摘要 View