Setting the Configuration using Toolbelt Configuration API
About Configuration
Configuration allows you to share values globally throughout your project. These values:
- Are Encrypted
- Are Stored at the project level and
- Don’t expire.
API keys, session keys, and other variables used across various cloud code actions are examples of configuration.
You can change the configuration using the Toolbelt Configuration API or Actions UI.
Code example
An example is to retrieve the secret key and use it to set the value.
async payload => {
try {
const secret = await toolbelt
.config
.get('secret_key')
// Make a GET call Check https://github.com/mzabriskie/axios for specifics
//we use secret_key config as api key to make a request
const result = await request.get(`https://api.themoviedb.org/3/movie/popular?api_key=${secret}`)
//return results of api request to message
return new Message(result.data.total_results)
} catch (err) {
console.log(err);
}
}
Setting a value
Use the toolbelt.config.set()
method to set and store data. The data must be provided as a key and value to save it.
A code snippet to set a value is given below.
async payload => {
const secret = await toolbelt
.config
.set('key','value')
}
Fetching a value
Use the get()
method to fetch the key value.
A code snippet to fetch the key value is given below:
async payload => {
const secret = await toolbelt
.config
.get('secret_key')
}
Note
If there are no data available, the
get()
method returns anull
value.
Removing values
Use the delete()
method to remove a specific key value.
A code snippet to remove a value.
async payload => {
// Remove a specific key
await toolbelt
.config
.delete('key')
}
Reference Fields for Methods
toolbelt.config.set(key, value)
Set the config value.
This method returns a promise
value.
Field Values and Description
Field | Type | Description |
---|---|---|
Key | string | A key value |
Value | string | A string to store |
promise | string | A promise that resolves with a set value. |
toolbelt.config.update(key, value)
Updates the config value.
This method returns a promise
value.
Field Values and Description
Field | Type | Description |
---|---|---|
Key | string | A key value |
Value | string | A string to store |
promise | string | A promise that will be resolved with the updated value. |
toolbelt.config.get(key)
Retrieve data from config by key.
This method returns a promise
value.
Field Values and Description
Field | Type | Description |
---|---|---|
Key | string | Key used to find the data |
promise | string | A promise that is resolved with the value being stored or null if the key does not exist. |
toolbelt.config.delete(key)
Remove data from config by key.
This method returns a promise value.
Field Values and Description
Name | Type | Description |
---|---|---|
Key | string | A key value |
promise | string | A promise that resolves with the deleted key data. |
Updated about 2 months ago