Rate this page:
This resource provides methods to store values in the Forge app storage, rather than product properties via the Properties API.
Data stored using the App storage API isn't shared between Forge apps on the same site or across different Atlassian sites.
The App storage API requires your app to have the storage:app
scope. See Add scopes to call an Atlassian REST API to add new scopes to your app.
Import the Forge API package in your app, as follows:
1
import { storage } from '@forge/api';
Stores a JSON value with a specified key. Persisted JSON values may be up to 32 KB in size and have a key of up to 100 bytes.
Note, write conflicts are resolved using a last-write-wins strategy.
1
storage.set(key: string, value: array | boolean | number | object | string ): Promise<void>;
Sets the key example-key
to one of the supported value types.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// array
storage.set('example-key', [ 'Hello', 'World' ]);
// boolean
storage.set('example-key', true);
// number
storage.set('example-key', 123);
// object
storage.set('example-key', { hello: 'world' });
// string
storage.set('example-key', 'Hello world');
Gets a value by key. If the key doesn't exist, the API returns undefined
.
1
storage.get(key: string): Promise<array | boolean | number | object | string>;
Gets the value associated with the key example-key
.
1 2
// Read the value for key `example-key`
await storage.get('example-key');
Deletes a value by key, this succeeds whether the key exists or not.
Note, write conflicts are resolved using a last-write-wins strategy.
1
storage.delete(key: string): Promise<void>;
Deletes the value associated with the key example-key
, if it hasn't already been deleted.
1 2
// Delete the value with the key `key`
await storage.delete('example-key');
Builds a query which returns a set of entities matching the provided list of criteria. See Query for more information on building and executing queries.
1
storage.query(): Query
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import { storage, startsWith } from '@forge/api';
await storage.query()
// Filter the response to only keys that start with the string 'value'
.where('key', startsWith('value'))
// Limit the result size to 10 values
.limit(10)
// Use the cursor provided (returned from a previous invocation)
.cursor('...')
// Get a list of results
.getMany();
To learn more about the App storage API:
Rate this page: