Knowledge Base API

Knowledge Base (KB) is a handy Automate database with a company-wide scope. This means that one KB is used across all of your projects.

πŸ‘‰ Learn more about Knowledge Base

When creating flows, you can access items stored in Knowledge Base by using Expression language (AEL). There are two ways to do this: using prefix knowledge or using a get() method. You can also check if the item exists by using exists() method. It is possible to use Expression language in Knowledge Base items' values so that they become dynamic.

Accessing Knowledge Base items

KB item's value can be of any data type available in Expression language. If an item is a JSON value, it will be interpreted as either an array or an object when accessed.

There are two methods to access KB item's value:

1. Withknowledge prefix

Access KB item's value by using knowledge prefix, the item's key and a dot notation.

Examples

In block's input field: knowledge.someKey.

In block's response field: "The current interest rate is {knowledge.percentage}".

2. With get() method

Access KB item's value using get() method. It allows you to define item's key using dynamic value, eg. knowledge.get(memory.kbItemName).

If you're providing a key literally, use quotation marks (eg. knowledge.get("someKey")). If you're providing a key that is stored as a dynamic value, ommit quotation marks (eg. knowledge.get(memory.kbItemName))

🚧

It is highly recommended not to use dots . in KB items' keys. Use other separators (like _ or -) instead.

Accessing JSON values stored as KB items

KB items recognize JSON as values and interpret them as either an array or an object when accessed. This is why you can access their specific properties or use array or object methods on them.

Example

In this example, knowledge.people is an array of objects.

To print the name stored in the first object (Paul), we would use such expression:

knowledge.people[0].name.

To print all of the names that aren't equal to "Matthew", we would use such expression:

knowledge.people.map(p => p.name).filter(n => n != "Matthew").join(", ")

πŸ‘‰ Learn more about: Arrays and Objects

Using exists() method to check if KB item by the provided key exists

Check if a KB item with given key exists by using exists() method.

knowledge.exists("someKey") 
// will return true when there is an item with such key in a KB
// will return false when there isn't an item with such key in a KB

Notes on KB item's values syntax

The fact that KB items' values can be interpreted as JSON causes a few edge cases:

  • Fully quoted text is a valid JSON and so quotation marks will be stripped. If you need to use quotation marks, then you need to escape them with \, eg. \"string in quotes\".
  • Numbers have a type of number (you can use arithmetics on them). If you want them to be strings, then use quotation marks, i.e. "55".
  • Other valid JSONs, e.g. [1] (an array with one element: number 1) will be treated as such. If you want them to be strings, escape them using quotation marks: "[1]".

Using dynamic values in KB items

It is possible to interpolate dynamic values and other expressions into KB item's value using curly brackets {}.

Example

In this example, knowledge.now will printThe current time is 2022-08-30 08:07., providing the current timestamp as date and time.


What’s Next