イベントストリームをフィルタリングする（Filter Your Event Streams）Postmanを使ったSalesforceのプロジェクトの解説*

Postmanを使ったSalesforceのプロジェクトの解説です。プロジェクト自体が日本語でないので、少々実際の画面も添付して操作の助けになればと思います。

全世界2,800万人以上の開発者に使われているAPIプラットフォームPostmanの記事を書こう by Postman Advent Calendar 2023のシリーズ 1　の10日目として作成しています。


+ [Filter Your Event Streams](https://trailhead.salesforce.com/ja/content/learn/projects/filter-your-platform-event-stream?trail_id=design-eventdriven-apps-for-realtime-integration)
イベント ストリームをフィルタリングして関連データを受信し、イベント処理を最適化します。

# Create a Custom Channel for Order Events

[Quick Start: Connect Postman to Salesforce](https://trailhead.salesforce.com/content/learn/projects/quick-start-connect-postman-to-salesforce)で設定した環境が必要です。

さて、まずはお決まり。何もしないで検証ボタンを押してみます。

:::note alert
We couldn't find the PlatformEventChannel with the name Order_Filtered_Channel__chn. Create this channel member by following the steps in this unit.
:::


1. Log in to your Trailhead Playground org.
2. After you set up Postman by completing the Quick Start: Connect Postman to Salesforce project, open the Postman app, select a Workspace, and navigate to your fork of the Salesforce API collection.
3. On the Authorization tab, scroll to the bottom and click Get New Access Token.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/da93300f-5900-1566-b11d-e46caacd738a.png)

ここで下にスクロール

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/fbe89a8e-e5d7-737f-e06c-da85b320d987.png)

4\. Click Allow.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/5e7870d1-56db-97ac-5df1-8c93bb0d4802.png)

5\.In the Manage Access Tokens dialog, copy the instance URL to your clipboard.
6\. Click Use Token. 

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/ef56de3e-dfd0-992b-8891-647a6ee14b3b.png)

7\. On the Variables tab, in the _endpoint row, in the CURRENT VALUE column, paste the instance URL that you just copied, then click Save. You may need to close the documentation pane to see the Save button.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/d6f254da-60a6-4f9d-cdee-d384c8ea2a38.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/dffcfc00-0cd3-0aef-9c7d-e22a0e13222c.png)


10\. Select REST to expand the REST APIs.
11\. Select GET Limits, then click Send.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/2d837945-4c5b-0538-b3c5-b36669d4eb6b.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/fc616b43-0f8e-4825-a0e9-1aa7ce2b4aaa.png)

12\. In the response window, the Status field should show as Status: 200 OK. If it does not, repeat the steps to get a new token.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/522c7db6-8d5f-9ae8-3822-2a0759af9cab.png)

**Make a Tooling API Call to Create a Custom Channel**

1. In your fork of the Salesforce APIs collection, expand **Event Platform > Custom Channels > Platform Event**, and **click Create channel**.
2\. Click Body and replace the body with this JSON body.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/43ab45df-c7f1-6707-1b6f-620ca61462a0.png)

4\. Verify that the response status is 201 Created.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/e099b50b-bf56-75c6-5a32-0dee35f08c37.png)

# Add the Order Event and the Filter Expression to a Channel Member

さて、まずはお決まり。何もしないで検証ボタンを押してみます。

:::note alert
We couldn't find the Order_Event__e platform event in your org. Follow the steps in this unit to define the platform event.
:::

Define the Order Platform Eventを完了した直後に検証ボタンをクリックします。

:::note alert
We couldn't find the PlatformEventChannelMember with the name Order_Filtered_Channel_chn_Order_Event_e. Create this channel member by following the steps in this unit.
:::

**Make a Tooling API Call to Create a Channel Member**

In your fork of the Salesforce APIs collection, expand **Event Platform > Custom Channels > Platform Event**, and click **Create channel member**.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/1fe3d7c3-c453-fd8f-5c8e-6140c1388df9.png)


# Subscribe to the Channel

何もしないで検証ボタンを押してみます。

何もしてないけど、合格してしまった。

まじめにインストールしようとすると、既にあるみたい？

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/c6ebd946-b03b-ff7f-0b29-01354dc0886b.png)

本当だ、すでにインストールされていた。　だから合格したのかもしれません。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/0fa7780c-422d-c637-94bc-24c1beac9240.png)

# Publish Order Events and Receive a Filtered Event Stream

何もしないで検証ボタンを押してみます。

これも何もしないでも合格してしまいましたねぇ。

1. In your fork of the Salesforce APIs collection, expand **Event Platform > Publish Platform Events**, and click **Publish multiple events**.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/c5196f79-0b9f-6730-135b-8e9096dc49ef.png)