Configuration
Configuration can be used to share values globally across the project. A good example would be an API key, session key, and any other variable used across multiple cloud code actions. Data is stored on the project level and never expires. Values are stored encrypted.
Configuration can be changed using the toolbelt configuration API or using the actions UI.
Code example
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);
}
}
Set a value
Storing data can be done using the toolbelt.config.set()
method. Provide a key and value to save.
async payload => {
const secret = await toolbelt
.config
.set('key','value')
}
Get a value
Fetch a value by key using the get()
method.
async payload => {
const secret = await toolbelt
.config
.get('secret_key')
}
Note
If no data exists
get()
will returnnull
Removing values
Remove a specific value by key.
async payload => {
// Remove aa specific key
await toolbelt
.config
.delete('key')
}
Reference
toolbelt.config.set(key, value)
Set config
Returns: Promise
- Promise that resolves with the value being set
Properties
Name | Type | Description |
---|---|---|
Key | string | Key to value |
Value | string | String to store |
toolbelt.config.update(key, value)
Set config
Returns: Promise
- Promise that resolves with the value being updated
Properties
Name | Type | Description |
---|---|---|
Key | string | Key to value |
Value | string | String to store |
toolbelt.config.get(key)
Retrieve data from config by key.
Returns: Promise
- Promise that resolved with the value being stored or null
if the key does not exist
Properties
Name | Type | Description |
---|---|---|
Key | string | Key used to find the data |
toolbelt.config.delete(key)
Remove data from config by key
Returns: Promise
- Resolves with the key of the deleted data
Properties
Name | Type | Description |
---|---|---|
Key | string | Key of the data to delete |
Updated 11 months ago