Talend Cloud API Tester allows you to manipulate data via functions.
Functions can create new data or transform existing data. The functions that transform data apply on the value of the expression they finish.
Usage examples
If you want to retrieve the first 10 planet names in the
list of planets in your Star Wars API, you can use the expression: ${"Star-wars API"."Get 10 planet
names"."response"."body".jsonPath("$.results[:10].name")}
. The method jsonPath
parses the result of the expression ${"Star-wars API"."Get 10 planet names"."response"."body"}
.
If you want to retrieve logs from the past week, you can create a URL with
expressions in the query parameters: https://myapi.com/logs?from=${timestamp().addTime("WEEK",
"-1")}&to=${timestamp()}
.
If you want to generate the
current date in ISO format, you can use the expression ${timestamp().formatDate('TIMESTAMP', 'ISO_8601')}
.
Constants
When writing an expression like ${"toto"}
, the expression is evaluated as:
- The value of the current environment's variable
toto
if there is one. - The request/scenario/service/project
toto
that is at root-level in your repository if no environment variable matched. - The string
toto
in any other case.
Data creation functions
Function | Description | Arguments | Example |
---|---|---|---|
timestamp
|
Returns the number of milliseconds from January 1, 1970, 00:00:00 GMT to the date when it is evaluated. | none | Expression: ${timestamp()}
Possible result: |
uuid
|
Returns a UUID. | none | Expression: ${uuid()}
Possible result: |
random
|
Returns a random number in range 0 <=
number < max . |
Maximum: defaults to 1000000000 | Expression: ${random(50)}
Possible result: |
randomString
|
Returns a random string with a specific length. Note: This function is not reliable for password generation and should not be
used for this purpose.
|
Length: number of characters in the string. Defaults to 10. [a-z]: select this check box to include lowercase letters in the string. [A-Z]: select this check box to include uppercase letters. [0-9]: select this check box to include numbers. |
Expression: ${randomString(10, true, true, true)}
Possible result: |
Data transformation functions
Function | Description | Arguments | Example |
---|---|---|---|
base64
|
Encodes in base 64. | none | Expression: ${"username:password".base64()}
Result: |
lower
|
Converts all the characters to lower case using the rules of the default locale. | none | Expression: ${"AbC".lower()}
Result: |
length
|
Computes the length of its input:
|
none | Expression: ${"Star-wars API"."Get 2
planets"."response"."body"}
Result:
Expression: Result: Result:
Expression: Result: |
substring
|
Returns a truncated input. |
Start: position of the first character that should be
extracted (0 by default). End: position of the first character that should be omitted (end of the input by default). Note: The index of the
first character is 0.
|
Expression: ${"0123456".substring(1)}
Result: Expression: Result: Expression: |
jsonPath
|
Returns the elements extracted from the JSON input with the given JSON path
selector . |
Selector: The JSON path selector that points to the part of the JSON to extract from the input. | Expression: ${"{\"titi\":
\"toto\"}".jsonPath("$.titi")}
Result: |
xPath
|
Returns the elements extracted from the XML input with the given XPath
selector . |
Selector: The XPath selector that points to the part of the XML to extract from the input. | Expression: ${"<title lang="en"
/>".xPath("//title/@lang")}
Result: |
hmac
|
Creates a Hash-based Message Authentication Code . |
Cipher: the hash function (SHA1 ,
SHA224 , SHA256 , SHA384 or
SHA512 ). Secret
: the secret key.
Output: the output type ( |
Expression: ${"test".hmac("sha256",
"secret", "Base64")}
Result: Expression: Result: |
sha
|
Hashes its input. |
Cipher: the hash function (SHA1 ,
SHA224 , SHA256 , SHA384 or
SHA512 ).
Output: the output type ( |
Expression: ${"toto".sha("SHA224",
"Base64")}
Result: Expression: Result: |
md5
|
Calculates the MD5 hash of its input. | none | Expression: ${"toto".md5()}
Result: |
upper
|
Converts all the characters to upper case using the rules of the default locale. | none | Expression: ${"aBc".upper()}
Result: |
string
|
Quotes its input. |
Quotes: the character that should be used to quote the
input. (' or " , " is
used by default). |
Expression: ${"toto".string()}
Result: Expression:
Result: Expression: Result: |
math
|
Performs the selected operation on the input value. |
Operation: ADD , SUBTRACT ,
MULTIPLY or DIVIDE
Value: number |
Expression: ${"7".math("MULTIPLY",
"6")}
Result: Expression: Result: Expression: Result: |
addTime
|
Adds or removes a number of the selected time unit from a date. |
Time unit: YEAR , MONTH ,
WEEK , DAY , HOUR ,
MINUTE or SECOND
Value: integer (you can use a negative number to remove a time unit) |
Expression: ${timestamp().addTime("YEAR",
"1")}
Possible result: Expression: Possible result: |
formatDate
|
Converts a date into the selected format. |
Input format: TIMESTAMP or
ISO_8601
Output format: |
Expression: ${timestamp().formatDate("TIMESTAMP",
"ISO_8601")}
Possible result: Expression:
Result: |