Commerce Cloud B2C Shop Connector 2.0 の例

Commerce Cloud B2C Shop コネクタは、操作ベースのコネクタです。つまり、コネクタをフローに追加するときに、コネクタで実行する特定の操作を設定する必要があります。 Commerce Cloud B2C Shop コネクタでは、2 種類の設定がサポートされています。 この例では、顧客認証接続プロバイダー設定を使用します。 Get Customer 操作が正常に実行されると、顧客の結果を取得できます。

このユースケースでは、次の手順を実行する必要があります。

Authorize Customer

  1. Authorize Customer​ 操作を実行して、Shopper JWT トークンを取得します。

  1. Anypoint Studio (Studio) で新しい Mule アプリケーションを作成し、ポート 8081 を HTTP リスナーとして、パスを「/customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login」として設定します。

shop connector authorize customer http listener config
  1. パレットからフローに操作「Authorize Customer」を追加します。

shop connector authorize customer
  1. postman から Authorize Customer 操作の必須パラメーターを取得します。

shop connector authorize customer body
  1. [Commerce Cloud B2C Shop Connector (Commerce Cloud B2C Shop コネクタ)] から [Commerce Cloud B2C Shop Connector Shopper Token Config (Commerce Cloud B2C Shop コネクタの Shopper トークン設定)] を選択し、必要な値で設定するか、緑のプラス記号 (+) をクリックして新しい設定を追加します。

shop connector shopper token config
  1. すべての必須パラメーターを入力したら、Mule プロジェクトを保存します。

  2. Package Explorer でプロジェクト名を右クリックし、[Run As (別のユーザーとして実行)] > [Mule Application (Mule アプリケーション)] を選択して、プロジェクトを Mule アプリケーションとして実行します。

  3. http://localhost:8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login​ に移動して Postman を開き、応答を確認します。

  4. レスポンスヘッダーに JWT トークンが表示されます。 この JWT トークンを Postman から認証ヘッダーパラメーターとして指定して、操作を実行できます。

Get Customer

  1. Anypoint Studio (Studio) で新しい Mule アプリケーションを作成し、ポート 8081 を HTTP リスナーとして、パスを「/customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId}」として設定します。

shop connector http listener config
  1. パレットからフローに操作「Get Customer」を追加します。

shop connector get customer flow
  1. postman から Get Customer 操作の必須パラメーターを取得します。

shop connector get customer body
  1. [Commerce Cloud B2C Shop Connector (Commerce Cloud B2C Shop コネクタ)] から [Commerce Cloud B2C Shop Connector Config (Commerce Cloud B2C Shop コネクタ設定)] を選択し、必要な値で設定するか、緑のプラス記号 (+) をクリックして新しい設定を追加します。

shop connector customer auth config
  1. 上記の画像では、Authorize Customer の認証トークンが認証パラメーター値として使用されています。

  1. すべての必須パラメーターを入力したら、Mule プロジェクトを保存します。

  2. Package Explorer でプロジェクト名を右クリックし、[Run As (別のユーザーとして実行)] > [Mule Application (Mule アプリケーション)] を選択して、プロジェクトを Mule アプリケーションとして実行します。

  3. http://localhost:8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId}​ に移動して Postman を開き、ヘッダーの Shopper JWT トークンを渡して、応答を確認します。

  4. 出力に顧客の詳細が表示されます。

Authorize Customer の XML

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:commerce-cloud-shopper-api="http://www.mulesoft.org/schema/mule/commerce-cloud-shopper-api"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:commerce-cloud-shopperapi="http://www.mulesoft.org/schema/mule/commerce-cloud-shopperapi"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/commerce-cloud-shopperapi http://www.mulesoft.org/schema/mule/commerce-cloud-shopperapi/current/mule-commerce-cloud-shopperapi.xsd
http://www.mulesoft.org/schema/mule/commerce-cloud-shopper-api http://www.mulesoft.org/schema/mule/commerce-cloud-shopper-api/current/mule-commerce-cloud-shopper-api.xsd">
	<flow name="guest-user-login-demoFlow">
		<http:listener
			doc:name="8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login"
			config-ref="HTTP_Listener_config"
			path="/customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login"
			allowedMethods="POST">
			<http:response>
				<http:headers><![CDATA[#[output application/java
---
{
"Authorization" : message.attributes.headers.Authorization }]]]></http:headers>

			</http:response>
			<http:error-response statusCode="#[error.errorMessage.attributes.statusCode]">
				<http:body><![CDATA[#[output text/json --- error.errorMessage.payload]]]></http:body>

			</http:error-response>
		</http:listener>
		<commerce-cloud-shopper-api:create-customer-shopper-customers-organizations-customers-actions-login-by-version-organization-id
			doc:name="Authorize Customer"
			version="#[attributes.uriParams.version]"
			organizationId="#[attributes.uriParams.organizationId]" clientId="#[attributes.queryParams.clientId]"
			siteId="#[attributes.queryParams.siteId]" authorization="#[attributes.headers.Authorization]" config-ref="Commerce_Cloud_B2C_Shop_Connector_Shopper_token"/>

	</flow>
</mule>

Authorize Customer のステップ

  1. 新しい Mule アプリケーションを作成します。

  2. キャンバスの下部にある [Configuration XML (設定 XML)] タブをクリックします。

  3. 上記のコードをコピーして貼り付けます。

  4. プロジェクトを保存します。

  5. Package Explorer でプロジェクト名を右クリックし、[Run As (別のユーザーとして実行)] > [Mule Application (Mule アプリケーション)] を選択して、プロジェクトを Mule アプリケーションとして実行します。

  6. http://localhost:8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login​ に移動して Postman を開き、応答を確認します。

  7. レスポンスヘッダーに JWT トークンが表示されます。この JWT トークンを Postman から認証ヘッダーパラメーターとして指定して、操作を実行できます。

Get Customer の XML

この例のフローをすばやく Mule アプリケーションに読み込むには、次のコードを Studio XML エディターに貼り付けます。

xml <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:commerce-cloud-shopper-api="http://www.mulesoft.org/schema/mule/commerce-cloud-shopper-api"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/commerce-cloud-shopper-api http://www.mulesoft.org/schema/mule/commerce-cloud-shopper-api/current/mule-commerce-cloud-shopper-api.xsd">
<flow name="get-customerFlow"> <http:listener doc:name="8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId}" config-ref="HTTP_Listener_config" path="/customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId}" allowedMethods="GET"> <http:error-response statusCode="#[error.errorMessage.attributes.statusCode]"> <http:body><![CDATA[#[output text/json --- error.errorMessage.payload]]]></http:body>

			</http:error-response>
		</http:listener>
		<commerce-cloud-shopper-api:get-customer-shopper-customers-organizations-customers-by-version-organization-id-customer-id
			doc:name="Get Customer"
			config-ref="Commerce_Cloud_Shopper_Connector_Customer_auth_config"
			version="#[attributes.uriParams.version]" organizationId="#[attributes.uriParams.organizationId]"
			customerId="#[attributes.uriParams.customerId]" siteId="#[attributes.queryParams.siteId]" />
	</flow>
</mule>

Get Customer のステップ

  1. 新しい Mule アプリケーションを作成します。

  2. キャンバスの下部にある [Configuration XML (設定 XML)] タブをクリックします。

  3. 上記のコードをコピーして貼り付けます。

  4. プロジェクトを保存します。

  5. Package Explorer でプロジェクト名を右クリックし、[Run As (別のユーザーとして実行)] > [Mule Application (Mule アプリケーション)] を選択して、プロジェクトを Mule アプリケーションとして実行します。

  6. http://localhost:8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId}​ に移動して Postman を開き、ヘッダーの Shopper JWT トークンを渡して、応答を確認します。

  7. 出力に顧客の詳細が表示されます。