hands‐on‐service‐integration‐n8n - DigiBP/digibp.github.io GitHub Wiki

Pizza Service – API Integration (Weather)

This hands-on extends the Pizza Service BPMN workflow with a service integration. Before delivery, a Service Task calls an n8n webhook, which retrieves the current weather for the customer's delivery location from wttr.in. The weather is returned to the BPMN process and displayed to the delivery service in a form.

Contents

1. BPMN Service Task and n8n Webhook

Watch the hands-on video 📹

In the Pizza Service workflow, configure Check current weather as an API CONNECT Service Task between Bake pizza and Deliver pizza. Create an n8n workflow with a Webhook node, set the HTTP method to POST, and copy its Test URL into the Service Task's URL field. Enable sending process variables to the API and receiving result variables back into the process. Start a test process instance to inspect the incoming data in n8n.

2. HTTP Request to the Weather API

Watch the hands-on video 📹

Add an HTTP Request node after the webhook. Use GET to retrieve current weather data from wttr.in. The delivery location is taken from the BPMN variable customerAddress, which is included in the webhook request body. Request a JSON response by adding the query parameter below.

URL (n8n expression):

https://wttr.in/{{ $json.body.customerAddress }}

Query parameter:

Name:  format
Value: j1

Set the response format to JSON, execute the node, and inspect the returned current_condition data.

3. Weather Field and Data Transformation

Watch the hands-on video 📹

In the Pizza Service form, add a read-only text field labelled Weather with the key weather. Then add an Edit Fields node in n8n to extract the weather description and temperature from the API response and combine them into a single string.

Output field:

weather

Value (n8n expression):

{{ $json.current_condition[0].weatherDesc[0].value }}, {{ $json.current_condition[0].temp_C }}°C

Example result:

{"weather": "Sunny, 10°C"}

4. Webhook Response and Testing

Watch the hands-on video 📹

Add a Respond to Webhook node after Edit Fields and select First Incoming Item. In the original Webhook node, set Respond to Using 'Respond to Webhook' Node. This returns the weather field to the BPMN process.

Deploy the updated BPMN process and form, start a Pizza Service instance, and complete Take pizza order and Bake pizza. At Deliver pizza, check that the current weather is displayed in the read-only field.

Note: The n8n Test URL works while listening for a test event. For regular execution, activate the n8n workflow and use its Production URL in the BPMN Service Task.