

 AWS Partner Central API 参考已重新构建。有关支持的 API 操作的更多信息，请参阅 [AWS Partner Central API 参考](https://docs.aws.amazon.com/partner-central/latest/APIReference/Welcome.html)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 最佳实践
<a name="best-practices"></a>

## 对事件做出反应
<a name="reacting-to-events"></a>

处理来自 Partn AWS er Central API 的事件时，请确保您的处理逻辑是等的，可以处理重复的事件。与其立即[GetOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_GetOpportunity.html)调用每个事件，不如考虑根据应用程序的需求批量或有选择地获取详细信息。要实现不间断的操作，请注意[配额](quotas.md)。

## 实现乐观锁定
<a name="implementing-optimistic-locking"></a>

乐观锁定可防止并发更新期间意外的数据覆盖。以下是一个典型场景：

1. 合作伙伴从其 CRM 系统中检索机会。

1. 用户在AWS合作伙伴中心`A`更新机会。

1. 用户通过 CRM 集成同时`B`更新相同的机会。

1. 如果数据发生变化，CRM 系统会尝试上传数据，但会返回`ConflictException`。

1. 用户查看错误并手动解决有冲突的数据。

为避免出现这种情况，所有[UpdateOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_UpdateOpportunity.html)请求都必须包含`LastModifiedDate`参数，您可以从之前的[CreateOpportunity[UpdateOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_UpdateOpportunity.html)](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_CreateOpportunity.html)、和[GetOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_GetOpportunity.html)操作中获取该参数。只有当我们的系统`LastModifiedDate`匹配时，更新才会成功。如果没有，则必须`LastModifiedDate`使用获取最新版本[GetOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_GetOpportunity.html)并重新尝试更新。

## 在 CRM 和之间同步数据AWS合作伙伴中心
<a name="synchronizing-data"></a>

必须使您的系统与合作伙伴中心的最新数据保持同步。以下是确保您的系统反映最新数据的两种策略：

### 使用事件（推荐）
<a name="using-events"></a>

1. 使用加载数据[ListOpportunities](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_ListOpportunities.html)。

1. 订阅机会活动。

1. 应对新的机会或变化。
   + 当您收到`Opportunity Created``Opportunity Updated`、或`Engagement Invitation Accepted`事件时`GetOpportunity`，使用获取最新数据。
   + 当您收到`Engagement Invitation Rejected`活动时，请删除相应的机会。

### 使用 ListOpportunities 投票
<a name="using-listopportunities-polling"></a>

1. 使用加载数据[ListOpportunities](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_ListOpportunities.html)。

1. 选择轮询频率，确保轮询频率不太高，以免耗尽每日[阅读](quotas.md)配额。

1. `LastModifiedDate`从存储的数据中识别最新数据，确保其源自AWS。

1. 调[ListOpportunities](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_ListOpportunities.html)用时使用`AfterLastModifiedDate`过滤器中的时间戳。

   ```
   {
      "FilterList": [
          {
              "Name": "AfterLastModifiedDate",
              "ValueList": [ "2023-05-01T20:37:46Z" ] // Replace with actual timestamp of your last synced data
           }
      ]
   }
   ```

1. AWS将返回在时间戳上显示的值之后创建或更新的机会。

1. 使用遍历所有返回的页面`NextToken`，并使用更新系统的数据。[GetOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_GetOpportunity.html)

   ```
   {
      "NextToken": "AAMA-EFRSN...PZa942D",
      "FilterList": [
          {
              "Name": "AfterLastModifiedDate",
              "ValueList": [ "2023-05-01T20:37:46Z" ] // Replace with actual timestamp of your last synced data
           }
      ]
   }
   ```