Contact Us 1-800-596-4880

B2C Shop Connector 1.0 Example - Mule 4

This example for Anypoint Connector for Salesforce Commerce Cloud B2C Shop APIs (B2C Shop Connector) example shows you how to:

  • Use the Authorize Customer operation to get a Shopper JWT token.

  • Use the Get Customer operation to view the customer’s details.

This example uses the B2C Shop Connector Customer Auth Connection Provider configuration.

Authorize Customer Flow

In this flow, you configure the HTTP Listener source and Authorize Customer operation to retrieve the Shopper JWT token from Postman:

  1. In Studio, select File > New > Mule Project.

  2. Enter a name for your Mule project and click Finish.

  3. In the Mule Palette view, select HTTP > Listener.

  4. Drag Listener to the Studio canvas.

  5. On the Listener configuration screen, optionally change the value of the Display Name field.

  6. Specify /customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login for the Path field:

    HTTP Listener General properties tab
  7. Click the plus sign (+) next to the Connector configuration field to configure a global element that can be used by all instances of HTTP Listener in the app.

  8. On the General tab, specify 8081 for Port.

  9. In the Mule Palette view, select the Authorize Customer operation and drag it on to the flow:

    Mule flow with HTTP Listener as the source and the Authorize Customer operation
  10. Obtain the required parameters for the Authorize Customer operation from Postman:

    Authorize Customer operation General tab
  11. Select the Commerce Cloud B2C Shop Connector, and then, in the Mule Palette view, select Commerce Cloud B2C Shop Connector Shopper Token Config and configure it with the required values:

    Commerce Cloud B2C Shop Connector Token Config General properties tab
  12. After entering all the required parameters, save the Mule project.

  13. Run the project as a Mule application by right-clicking the project name in Package Explorer and selecting Run As > Mule Application.

  14. Navigate to http://localhost:8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/actions/login.

  15. Open Postman and check the response, noting the JWT Token in the response header.

You can use this JWT Token as the authorization header parameter in Postman to perform operations.

XML for the Authorize Customer Flow

Click the Configuration XML tab at the base of the canvas and copy and paste the following XML code into the Studio XML editor to quickly load the flow for this example into your Mule app:

<?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>

Get Customer Flow

In this flow, you configure the HTTP Listener source and Get Customer operation to retrieve and view the customer’s details:

  1. In Studio, select File > New > Mule Project.

  2. Enter a name for your Mule project and click Finish.

  3. In the Mule Palette view, select HTTP > Listener.

  4. Drag Listener to the Studio canvas.

  5. On the Listener configuration screen, optionally change the value of the Display Name field.

  6. Specify /customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId} for the Path field:

    HTTP Listener General properties tab
  7. Click the plus sign (+) next to the Connector configuration field to configure a global element that can be used by all instances of HTTP Listener in the app.

  8. On the General tab, specify 8081 for Port.

  9. In the Mule Palette view, select the Get Customer operation and drag it onto the flow:

    Mule flow with HTTP Listener as the source and the Get Customer operation
  10. Obtain the required parameters for the Get Customer operation from Postman:

    Get Customer General properties tab with values for Version
  11. Select the Commerce Cloud B2C Shop Connector Config from the Commerce Cloud B2C Shop Connector and configure it with the required values, or add a new configuration by clicking the green plus (+) sign:

    Commerce Cloud B2C Shop Connector Config General properties tab

    The authentication token from Authorize Customer shown here is used as the Authorization parameter value.

  12. After entering all the required parameters, save the Mule project.

  13. Run the project as a Mule application by right-clicking the project name in Package Explorer and selecting Run As > Mule Application.

  14. Navigate to http://localhost:8081/customer/shopper-customers/{version}/organizations/{organizationId}/customers/{customerId}.

  15. Open Postman, and provide the JWT Token (xref:Authorize Customer<Shopper JWT Token>) from the header.

  16. Check the response to see the customer details.

XML for the Get Customer Flow

Click the Configuration XML tab at the base of the canvas and copy and paste the following XML code into the Studio XML editor to quickly load the flow for this example into your Mule app:

<?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>
View on GitHub