About this workflow
Convert the JSON data received from the CocktailDB API into XML
This N8n workflow template is designed to fetch random cocktail data from the TheCocktailDB public API in JSON format and convert it into XML format using built-in data transformation capabilities. The workflow demonstrates a simple yet practical integration and data conversion pipeline, ideal for users who need to transform JSON responses from REST APIs into XML for downstream systems that require or prefer XML-based data.
What the Workflow Does
The workflow initiates on manual execution, sends an HTTP GET request to retrieve a random cocktail's details from TheCocktailDB API, and then transforms the returned JSON response into an XML document. This enables seamless interoperability between modern JSON-based APIs and legacy or enterprise systems that operate with XML.
Key Features and Capabilities
- Manual Trigger Execution: The workflow runs only when manually triggered, making it suitable for on-demand data retrieval.
- HTTP Request Integration: Directly connects to a live public REST API without requiring authentication.
- Data Format Conversion: Uses the native XML node in n8n to convert structured JSON into well-formed XML.
- Lightweight and Reusable: Minimal node setup makes this workflow easy to understand, modify, and reuse in larger workflows.
- No External Dependencies: Relies only on n8n’s core nodes—Manual Trigger, HTTP Request, and XML—ensuring compatibility across n8n environments.
Main Nodes and Their Purposes
-
On clicking 'execute' (Manual Trigger Node)
- Purpose: Serves as the starting point of the workflow.
- Function: Waits for the user to click the "Execute Workflow" button in the n8n interface to begin the process.
- Type:
n8n-nodes-base/manualTrigger
-
HTTP Request Node
- Purpose: Retrieves real-time cocktail data from an external API.
- Function: Sends a GET request to
https://www.thecocktaildb.com/api/json/v1/1/random.php, which returns a random cocktail in JSON format (e.g., name, ingredients, instructions, image). - Type:
n8n-nodes-base/httpRequest - Key Parameter: URL set to the CocktailDB random drink endpoint.
-
XML Node
- Purpose: Converts the incoming JSON payload into XML format.
- Function: Operates in
"jsonToXml"mode, transforming the structured JSON response from the HTTP Request into a valid XML string. - Type:
n8n-nodes-base/xml - Mode:
jsonToxml— ensures directional conversion from JSON to XML.
Use Cases and Benefits
- System Integration: Useful when integrating with legacy systems or third-party tools that accept only XML input (e.g., older ERP, CMS, or EDI systems).
- Data Standardization: Enables standardization of data formats across heterogeneous environments.
- Prototyping & Testing: Ideal for developers testing API responses or building proof-of-concept integrations involving format translation.
- Learning Tool: Excellent for beginners learning how n8n handles API calls and data transformations.
- Automation Prep: Can be extended to auto-trigger via webhooks or schedules and feed converted XML into email, file storage, or message queues.
Step-by-Step Workflow Logic
-
Step 1: Workflow Initiation
- The user manually executes the workflow by clicking the “Execute” button.
- The Manual Trigger node activates and passes control to the next node.
-
Step 2: Fetch Cocktail Data
- The HTTP Request node sends a GET request to
https://www.thecocktaildb.com/api/json/v1/1/random.php. - The API responds with a JSON object containing details about a randomly selected cocktail, including its name, ingredients, measurements, instructions, and more.
- The HTTP Request node sends a GET request to
-
Step 3: Convert JSON to XML
- The JSON response is passed to the XML node.
- The node processes the JSON structure and converts it into an equivalent XML representation.
- For example, a JSON field like
{"strDrink": "Margarita"}becomes<strDrink>Margarita</strDrink>within a root<root>element (default unless customized).
-
Output
- The final output is a formatted XML string that mirrors the original JSON data.
- This XML can be used in subsequent nodes such as File Binary, Email, or Webhook Responders for further processing or delivery.
This workflow exemplifies n8n’s strength in handling API integrations and data transformations with minimal configuration, making it accessible for both technical and non-technical users.
How to use: download the JSON, then in n8n choose “Import from File”.