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
Code Templates are methods injected into the Lab Scripter, to all its instances before the code runs. Those methods can be written in the Code Templates tab and they can be implemented in Ruby or Python.
Please be careful updating Production and use Tester for validation. In each Scripter step, you can choose which code template to use.
Click here for a detailed automation use case