Create a short order ID with webhooks

Last updated: 01 May 2019

This example demonstrates how you can create short order IDs using Moltin webhooks.

Running locally

When using this example locally, it's recommended you use a service ngrok to tunnel your dev environment to the outside world.

Once you have the repo running locally, you'll want to add the integration via the Moltin Dashboard. The URL will be the one provided by ngrok.

1. Download the example

Clone the repository:

git clone git@github.com:moltin/integration-examples.git

Install the dependencies with Yarn

cd integration-examples/short-order-id
yarn

2. Configure Flows

Moltin provides you the ability to extend core resources with the Flows API. From inside the Moltin Dashboard, head to Settings > Flows.

Here you will want to create a new Flow (or edit if it already exists) for extending products. Give it a name and description, and make sure the slug is set to products.

52850827-65468600-310c-11e9-9caa-c82a0175acd9

Next you will want to create a new Field for the Flow you just created.

52850885-96bf5180-310c-11e9-93d0-85821730d0d9

Give the new Field a name and description you will recognise. Make sure the slug is set to short_id as this is what the serverless function cloned above expects.

52850990-dbe38380-310c-11e9-95b1-dc07b753a3a9

Save this Field.

3. Configure your ENV variables

You will want to create an .env inside the directory /short-order-id containing all the keys for the below:

MOLTIN_CLIENT_ID=
MOLTIN_CLIENT_SECRET=
MOLTIN_WEBHOOK_SECRET=

MOLTIN_WEBHOOK_SECRET can be anything you want.

4. Start the server and ngrok

Start the development server

yarn dev

The server will typically start on PORT 3000. If not, make a note for the next step.

Start ngrok

ngrok http 3000

This will expose PORT 3000 to the outside world. Make a note of the URL ngrok provides.

5. Create a new Moltin integration

You must now tell Moltin the ngrok URL above. From within the Moltin 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

52846929-ca957980-3102-11e9-9a20-23b8139767ee

Now finally you'll want to configure this webhook to be invoked when an order is Created.

52851227-76dc5d80-310d-11e9-9dff-70b7daaf21e8

That's it! Click Save 🎉