# Ruby snippets by Workato
Ruby is a popular language for web development. The Ruby snippets by Workato connector enables you to write custom Ruby code and insert it into your recipe to execute a custom action. This allows you to use Ruby to perform actions such as invoking external services.
ALLOWLISTED RUBY METHODS ONLY
Only allowlisted Ruby methods can be added to your recipe. Refer to Available Ruby methods for more information.
No connection set up is required to use the Ruby snippets by Workato connector.
Ruby snippets by Workato
# Required sections
Section | Description |
---|---|
Name | Provide a descriptive name that indicates the purpose of the action. For example, Get account details . |
Input | Use this section to pass data into your Ruby code. |
Output schema | Use this section to define the data structure that your Ruby code outputs. |
Code | Use this section to add the Ruby code you plan to execute. This code can use the data passed in the Input section and must return a hash that matches the structure defined in the Output schema section. |
30-SECOND TIMEOUT
Your Ruby action times out after 30 seconds.
# Input
The Input section in your Ruby snippet allows you to pass data into the Ruby code. This can be data from a previous step in the recipe or any other data you plan to use within your Ruby code. You can access the data in the Input section using the input
keyword in your Ruby code.
Input section
You must define the input fields you plan to use in your action:
Navigate to the Input section.
Click Add field.
Add a Label to your input.
Add new field
Use the Data type drop-down menu to select the data type you plan to use, such as string or boolean.
Optional. Enter a description or provide additional context to help users in the Hint field.
Click Add field to add the input field to your action.
Repeat these steps for all input fields you plan to pass to your Ruby code.
# Output schema
The output schema defines the data structure that your Ruby code outputs. This is useful if you plan to use the output of the Ruby code in subsequent recipe steps.
You must define the output schema for the code when you use Ruby snippets by Workato to execute an action. The output schema builds the output datatree, allowing you to use the data returned from the Ruby function in subsequent recipe actions.
Output schema
You can configure the output schema by using sample JSON or by manually defining output fields.
# Manually define output fields
Complete the following steps to manually add fields to your output schema:
Navigate to the Output schema section.
Click Add fields manually.
Manually define your output schema
Enter a Name for your field.
Optional. Add a Label to your input.
Use the Data type drop-down menu to select the data type you plan to use, such as string or boolean.
Use the Optional drop-down menu to select whether the field is optional or required.
Optional. Use the Nest under drop-down menu to select where to nest the field.
Optional. Enter a description or provide additional context to help users in the Hint field.
Click Add field to add this field to your output schema.
Repeat these steps for all fields you plan to pass to your Ruby code.
# Use sample JSON
Complete the following steps to configure your output schema with sample JSON:
Click the Use JSON button to open the schema generation wizard.
Define your output schema with sample JSON
Paste the JSON sample you plan to use in the window and click Next.
Review the JSON sample and then click Generate schema. The output datatree appears in the Output fields.
# Code
The Code field is where you write the Ruby code that your recipe executes. This code can use the data from the Input field and must return a hash that matches the structure defined in the Output schema field. The keys in the returned hash must match the field names in the Output schema, and the corresponding values contain the data for those fields.
Add your Ruby code
Last updated: 6/6/2024, 6:03:35 AM