Synchronize search with Algolia
In this example, we clone and configure the repository containing the code necessary to synchronize data between Elastic Path Commerce Cloud and Algolia by using webhooks.
Step-by-step walkthrough
- Prepare to run the example locally
- Download the example
- Configure Algolia
- Configure your environment variables
- Create a new integration
Prepare to run the example locally
When using this example locally, itʼs recommended you use a service ngrok to tunnel your dev environment to the outside world.
After you have the repo running locally, add the integration through the Dashboard. The URL is the one provided by ngrok.
Download the example
Clone the repository:
git clone git@github.com:moltin/integration-examples.git
Install the dependencies with Yarn
cd integration-examples/sync-catalog-to-algolia
yarn
Configure Algolia
In this example, we synchronize data to Algolia. After you sign up to Algolia, you need to create a new app and give it a name.
Next head to the API keys section and make a note of your Application ID and Admin API Key, we need these next.
Configure your environment variables
Create an .env file inside the directory /short-order-id
containing all the keys for the following environment variables:
MOLTIN_CLIENT_ID=
MOLTIN_CLIENT_SECRET=
MOLTIN_WEBHOOK_SECRET=
MOLTIN_WEBHOOK_SECRET
can be anything you want.
Start the server and ngrok
Start the development server
yarn dev
The server typically starts on port 3000. If not, make a note for the next step.
Start ngrok
ngrok http 3000
This exposes port 3000 to the outside world. Make a note of the URL ngrok provides.
Create a new integration
You must now tell Commerce Cloud the ngrok URL specified previously. From within the Dashboard, head to Settings > Integrations and click Create.
Enter a name and description for your integration. It might be useful to prefix the name with DEVELOPMENT
for easier referencing.
Next, enter the ngrok URL and Secret Key that matches that inside .env
.
Now youʼll want to configure this webhook to invoke your serverless function when any of the catalog resources are created, updated, or deleted.
Click Save.
Further reading
- Events (Webhooks)
- Events (Webhooks) API
- Synchronize search example (Source code)