

 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>

從AWS Partner 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. 使用者`A`更新AWS Partner Central 上的機會。

1. 使用者透過 CRM 整合同時`B`更新相同的機會。

1. 如果資料變更，CRM 系統會嘗試上傳資料，但會傳回 `ConflictException`。

1. 使用者檢閱錯誤並手動解決衝突的資料。

若要避免這種情況，所有 [UpdateOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_UpdateOpportunity.html) 請求都必須包含 參數，您可以從先前的 [CreateOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_CreateOpportunity.html)、[UpdateOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_UpdateOpportunity.html) 和 [GetOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_GetOpportunity.html) 動作取得該`LastModifiedDate`參數。只有在 `LastModifiedDate`符合我們的系統時，更新才會成功。如果沒有，您必須`LastModifiedDate`使用 [GetOpportunity](https://docs.aws.amazon.com/partner-central/latest/APIReference/API_GetOpportunity.html) 擷取最新的 ，並重新嘗試更新。

## 在 CRM 和AWS Partner Central 之間同步資料
<a name="synchronizing-data"></a>

請務必讓您的系統與 Partner Central 的最新資料保持同步。以下是確保系統反映最新資料的兩個策略：

### 使用事件 （建議）
<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
           }
      ]
   }
   ```