Rate this page:

App storage API

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';

storage.set

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.

Method signature

1
storage.set(key: string, value: array | boolean | null | number | object | string ): Promise<void>;

Example

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
15
16
17
// array
storage.set('example-key', [ 'Hello', 'World' ]);

// boolean
storage.set('example-key', true);

// null
storage.set('example-key', null);

// number
storage.set('example-key', 123);

// object
storage.set('example-key', { hello: 'world' });

// string
storage.set('example-key', 'Hello world');

storage.get

Gets a value by key. If the key doesn't exist, the API returns undefined.

Method signature

1
storage.get(key: string): Promise<array | boolean | number | object | string>;

Example

Gets the value associated with the key example-key.

1
2
// Read the value for key `example-key`
await storage.get('example-key');

storage.delete

Deletes a value by key, this succeeds whether the key exists or not.

Note, write conflicts are resolved using a last-write-wins strategy.

Method signature

1
storage.delete(key: string): Promise<void>;

Example

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');

storage.query

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.

Method signature

1
storage.query(): Query

Examples

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();

More information

To learn more about the App storage API:

  • Find out how to query against data stored in the App storage API.
  • Explore the App storage API reference for more details on how it works.
  • View the limits that apply to apps using the App storage API.

Rate this page: