evaluate
Evaluate a CQL query in real-time.
This method evaluates a CQL query in real-time and returns the result.
For more information, see Query evaluation.
Signature
This method has the following signature:
croct.evaluate<T extends JsonValue>(query: string, options: EvaluationOptions): Promise<T>;
The return is a Promise that resolves to the evaluation result.
Example
Here is a basic example of how to use this method:
import croct from '@croct/plug';croct.evaluate("user's interests").then(console.log);
For more examples, see the Query evaluation reference.
Parameters
The following list describes the supported parameters:
- querystring
The CQL query to evaluate, with a maximum length of 500 characters.
- options(optional)object
The evaluation options.
- timeout(optional)number
The maximum fetch time in milliseconds.
Good to knowYou can set a default timeout for your application during SDK initialization, eliminating the need to specify it each time.
Once reached, the SDK will abort the request and reject the promise with a timeout error.
- attributes(optional)object
The map of attributes to inject in the evaluation context.
The attributes can be referenced in audience conditions using the context variable. For example, suppose you pass the following attributes:
{cities: ["New York", "San Francisco"]}You can then reference them in queries like:
context's cities include location's cityFor more information, see Context variables.
The following restrictions apply to the attributes:
- Up to 30 entries and 5 levels deep
- Keys can be either numbers or non-empty strings with a maximum length of 50 characters
- Values can be null, numbers, booleans, strings (up to 50 characters), or nested maps
- Nested maps follow the same constraints for keys and values
- timeout(optional)