Generating a Flow Diagram from a Workato Recipe ID
Table of contents
- Prerequisites
- Step1: Installation
- Step 2: Environment Setup in Local Machine or Remote Server
- Building the Workato Recipe
- Step 1: Fetching the Workato Recipe details
- Step 2: Generating the required Recipe JSON Schema Using Python
- Step 3: Saving the transformed Recipe JSON File to the Inbound Location
- Step 4: Execute the Python Script to Generate the Flow Diagram
- Step 5: Archive the Inbound Files
- Step 6: Download the Flow Diagram
- Step 7: Upload the Recipe Flow Diagram to Share point
- Step 8: Sample Output
- Conclusion
-Bala Tadisetty
In this article, we will walk you through the process of generating a flow diagram from a Workato recipe ID. This is particularly useful for visualizing complex workflows and understanding the sequence of actions and conditions within your recipes. We will use Python and Graphviz to accomplish this.
Prerequisites
Step1: Installation
Before we begin, make sure you have the following installed on your system:
Python 3.x
Graphviz
The
graphviz
Python library
You can install the required Python library using pip:
pip install graphviz
Additionally, ensure that Graphviz is installed on your system and its executables are added to your system's PATH. You can download Graphviz from here.
Step 2: Environment Setup in Local Machine or Remote Server
Create the below folders
C:\RecipeToFlow\Script\recipetoflow.py
C:\RecipeToFlow\Files\Inbound
C:\RecipeToFlow\Files\Inbound\Archive
C:\RecipeToFlow\Files\Outbound
C:\RecipeToFlow\Files\Outbound\Archive
2.Update the recipetoflow.py with below script
import json
def extract_data(data):
extracted_data = []
if isinstance(data, dict):
# Extract data from the current dictionary
extracted_data.append({
"number": data.get("number"),
"provider": data.get("provider"),
"name": data.get("name"),
"title": data.get("title"),
"keyword": data.get("keyword"),
"comment": data.get("comment"),
"skip": data.get("skip"),
})
# Recursively call the function on the "block" list for nested data
if "block" in data:
for block in data["block"]:
extracted_data.extend(extract_data(block))
return extracted_data
def main(input):
# Extract data and print the result
extracted_data = extract_data(json.loads(input['JSON']))
extracted_data_json = json.dumps(extracted_data)
# print(extracted_data_json)
return extracted_data_json
Update Workato Onprem Config file as below
Building the Workato Recipe
Step 1: Fetching the Workato Recipe details
First, you need to fetch the Workato recipe using its ID. You can do this through Workato's API. Here’s an example of how you can fetch the recipe details using HTTP action:
Step 2: Generating the required Recipe JSON Schema Using Python
Use the Python application in recipe flow and add the input fields as below
Use the below Python code to perform the transformation.
import json
def extract_data(data):
extracted_data = []
if isinstance(data, dict):
#Extract data from the current dictionary
extracted_data.append({
"number": data.get("number"),
"provider": data.get("provider"),
"name": data.get("name"),
"title": data.get("title"),
#"description": data.get("description"),
"keyword": data.get("keyword"),
"comment": data.get("comment"),
"skip": data.get("skip"),
})
#Recursively call the function on the "block" list for nested data
if "block" in data:
for block in data["block"]:
extracted_data.extend(extract_data(block))
return extracted_data
def main(input):
#Extract data and print the result
extracted_data = extract_data(json.loads(input['JSON']))
extracted_data_json = json.dumps(extracted_data)
#print(extracted_data_json)
return extracted_data_json
#return input['JSON']
Step 3: Saving the transformed Recipe JSON File to the Inbound Location
Once you have fetched the required JSON file. Write this output to the Inbound location. Save the file with <<Recipe_id>>.json
Step 4: Execute the Python Script to Generate the Flow Diagram
To generate the flow diagram, run the script by passing Recipe id as input. This generate a flow diagram named recipe_id.gv.pdf
Step 5: Archive the Inbound Files
Step 6: Download the Flow Diagram
Step 7: Upload the Recipe Flow Diagram to Share point
Step 8: Sample Output
Conclusion
In this article, we've shown you how to generate a flow diagram from a Workato recipe ID using Python and Graphviz. This visual representation can help you better understand and analyze your workflows. Feel free to customize the script further to suit your specific needs.
Subscribe to my newsletter
Read articles from Bala Subramanyam directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by