secret[] method

Returns the value of an HCL password variable.

Note

You must first create the HCL variable and assign a value in the Variables window in the Robots script editor. Unlike Python variables, you cannot create HCL variables directly in a script.

Syntax

hcl.secret["variable_name"]
hcl.secret["variable_name"].unmask()

Parameters

Name Description
variable_name

The name of the HCL password variable.

Returns

hcl.variables.Secret object (masked).

String (unmasked).

Examples

Return the value of an HCL password variable

Returns ******, which is the masked value of the v_password HCL variable.

hcl.secret["v_password"]

Returns 'my_password', which is the unmasked value of the v_password HCL variable.

hcl.secret["v_password"].unmask()

Use an HCL password variable in an API request

The example below connects to the Open Exchange Rates API and returns the exchange rates for the five specified currencies. Before connecting, the Open Exchange Rates token stored in the HCL password variable v_oxr_token is copied to the regular Python variable oxrtoken.

# Assign your Open Exchange Rates token to a Python variable
oxrtoken = hcl.secret["v_oxr_token"].unmask()

# Connect to the Open Exchange Rates API and return the latest exchange rates for the specified currencies relative to USD
response = requests.get(f"https://openexchangerates.org/api/latest.json?app_id={oxrtoken}&symbols='CNY','EUR','GBP','MXN','USD'")
response.json()

Remarks

The HCL password variable supports long passwords or authentication tokens. The variable value can be up to 8 KB in length.

For more information, see Using variables in a Python/HCL script.