Using the Lab scripter step:
General use:
Use either Python or Ruby to write your custom code.
Name the step by using the 'Explanation' field. The name will appear in the log and will help orientation.
Use the 'Output variables' field to make a variable generic to use in further steps:
β
βUseful commands:
token() - Generates a token dynamically without the need to store it locally. Token cannot be printed, but can be used in an API request body
base() - Generates the domain dynamically in the URL for API requests, for example:
response = requests.get(f'{base()}/api/v1/stocks', json={"token":token()})
Print / Log- Use the Print/Log functions to add comments to the logs found under the Runs tab. i.e. print(x) or print("Experiment Id is #{variable_name}") (in Python) - this is useful for debugging and for having more informative logs.
log(x) *IN RUBY*
print(x) *IN PYTHON*Using Variables - To use a variable that was defined in the preceding steps in the scripter, use the function:
X = variable('variable_name')
βStore Variables - To use variables created in the Scripter step in downstream steps, use this function:
store_variable("new_name_of_variable", name_used_in_Lab_scripter)
Then, add the new variable name in the 'Output variables' field at the bottom of the step. You can add multiple variables by using the store_variable function for each one and then naming all of them in 'Output variables' separated by a comma.
Using the API
To make GET, POST, and PUT requests in the Scripter, use the get_api, post_api, and put_api methods that can be found in the list of methods. For more information on Labguru's API visit our API documantation.
β
Using the Code template feature
The Code Template option allows you to write common methods that can be used across different flows. These methods can be injected into any instance of the Scripter step, eliminating the need to rewrite them for each flow.
Methods can be written in either Ruby or PythonTo call a method from the Code Template, make sure to select the relevant template (either Tester or Production) in the Scripter step.
Click here for a detailed automation use case