Data Store REST API Reference
Use the Data Store REST API to update the data store on an Alexa-enabled device with a screen. You can push updates to the data store from requests sent to your skill and from outside of a skill session. The data store is an area installed locally to a device that contains data an Alexa Presentation Language (APL) document can access with data binding. Widgets use the data store to display content without sending requests to your skill and waiting on a response.
You can update the data store for a list of specific devices or for a specific user.
For details about widgets, see About Widgets and Alexa Presentation Language (APL).
Data store organization
The data store on a device is organized by region, namespace, and key. A region can contain multiple namespaces, and a namespace can contain multiple keys. Each key contains an object with the data.
Each data store command has properties to specify the namespace
and key
as needed. The Data Store API determines the region for your skill based on the skill ID. Your skill can't access the data store for any other skills. For more details, see .
Each data store command has properties to specify the namespace
and key
as needed. The Data Store API determines the region for your skill based on the skill ID. Your skill can't access the data store for any other skills. For more details, see Data binding and the data store.
Data store limits
The data store imposes the following limitations:
- A skill can store up to 1 MB of data on a device. This limit is per skill and is shared across all the widgets associated with the skill. Each item in the region, including the
namespace
andkey
names, contributes to storage consumed by the skill. - Your skill can't exceed 25 transactions per second (TPS) when it writes data to the data store.
API endpoint
Use one of the following endpoints, based on the region for your skill:
- North America:
https://api.amazonalexa.com
- Europe:
https://api.eu.amazonalexa.com
- Far East:
https://api.fe.amazonalexa.com
Authentication
Each API request must have an authorization header whose value is the access token retrieved from Login with Amazon (LWA).
For details, see Get access token with skill credentials operation. In the request body, set the scope to alexa::datastore
.
Operations
The Data Store API includes the following operations.
Operation | HTTP method and URI |
---|---|
| |
| |
|
Cancel
Cancels a pending request for a specified queued result. Use this command to cancel a previous request issued with the Commands operation.
Request
To cancel a request, you make a POST
request to the /v1/datastore/queue/<queuedResultId>/cancel
resource.
Request path and header example
POST /v1/datastore/queue/<queuedResultId>/cancel
Content-Type: application/json
Authorization: Bearer {access_token}
Request path and header parameters
Parameter | Located in | Description | Type | Required |
---|---|---|---|---|
|
Path |
Unique identifier to query for queued delivery for offline devices. Retrieve this identifier from the response from the Commands operation. |
String |
Yes |
|
Header |
Access token for your skill. Use your client credentials and the scope to obtain the access token. For details, see Authentication. |
String |
Yes |
Request body example
The request has no body.
Request body properties
The request has no body.
Response
A successful response returns HTTP 204 No Content
.
On error, the response returns the appropriate HTTP status code and includes a response body with an Error object.
Response body example
The response has no body.
Response body properties
The response has no body.
HTTP status codes
Status | Description |
---|---|
|
Pending request successfully canceled. |
|
Indicates that one or more properties in the request body aren't valid.
|
|
Request didn't include the authorization token, or the included token expired or isn't valid. Or, you don't have access to the resource.
|
|
Indicates that the authorization token is valid, but the requested operation isn't allowed.
|
|
Permitted rate limit, specified as number of requests per unit of time, exceeded. Retry the request by using exponential back-off. |
|
Error occurred on the server. Retry the request by using exponential back-off.
|
Commands
Runs the specified set of commands to update the data store for a list of devices or users. For details about the commands you can run, see Data store commands. If devices are offline, the command is queued until the device comes back online. Use the Queued result query to get the status of the queued commands.
Request
To run the set of commands to update the data store, you make a POST
request to the /v1/datastore/commands
resource.
Request path and header example
POST /v1/datastore/commands
Content-Type: application/json
Authorization: Bearer {access_token}
Request path and header parameters
Parameter | Located in | Description | Type | Required |
---|---|---|---|---|
|
Header |
Access token for your skill. Use your client credentials and the scope to obtain the access token. For details, see Authentication. |
String |
Yes |
Request body example
{
"commands": [
{
"type": "PUT_OBJECT",
"namespace": "NamespaceMainPage",
"key": "keyMainPage",
"content": {
"mainPageContent": {
"lastUpdated": "Sent this update on April 17, 2023."
}
}
}
],
"target": {
"type": "DEVICES",
"items": [
"amzn1.ask.device.1",
"amzn1.ask.device.2"
]
},
"attemptDeliveryUntil": "2024-01-31T10:00:00.00Z"
}
Request body properties
Property | Description | Type | Required |
---|---|---|---|
|
Collection of ordered commands to run to update the data store. For details about the format of the commands, see Data store commands. |
Array of data store commands |
Yes |
|
Identifies the target for the commands. Include either a list of device IDs or one user ID. |
Target object |
Yes |
|
When provided, Alexa makes additional attempts to deliver the commands if a device is unreachable on the first attempt. Maximum value is 48 hours after sending the request. Inspect the When not provided, Alexa doesn't attempt to redeliver the commands to unreachable devices. |
String |
No |
Response
A successful response returns HTTP 200 OK
, along with the results for each device.
On error, the response returns the appropriate HTTP status code and includes a response body with an Error object.
Response body example
The following example shows the response body for a commands operation that attempted to update two devices. In this example, Alexa updated the first device, but failed to update the second device because it wasn't available.
{
"results": [
{
"deviceId": "amzn1.ask.device.1",
"type": "SUCCESS"
},
{
"deviceId": "amzn1.ask.device.2",
"type": "DEVICE_UNAVAILABLE",
"message": "AOGS: Send directive failure: Device unreachable"
}
],
"queuedResultId": "<id-for-this-result>"
}
Response body properties
Property | Description | Type |
---|---|---|
|
List of results for each target user or device. Each item in this array indicates whether the operation was successful for the specified device. The items in the
|
Array of objects |
|
ID of the device that Alexa attempted to update. |
String |
|
Formatted as an Amazon Common Identifier (ACI),
|
String |
|
(Optional) Message that describes the error. |
String |
|
(Optional) Applies when at least one device was offline ( Not provided when no devices in the request were offline. |
String |
HTTP status codes
If the operation returns any status other than HTTP 200 OK
, the process stopped before Alexa attempted to update the devices.
Status | Description |
---|---|
|
The Data Store API parsed and validated the request and attempted to deliver the payload to the provided targets. Results for each device are available as part of the response body in the |
|
Indicates that one or more properties in the request body aren't valid.
|
|
Request didn't include the authorization token, or the included token expired or isn't valid. Or, you don't have access to the resource.
|
|
Indicates that the authorization token is valid, but the requested operation isn't allowed.
|
|
Permitted rate limit, specified as number of requests per unit of time, exceeded. Retry the request by using exponential back-off. |
|
Error occurred on the server. Retry the request by using exponential back-off.
|
Queued result query
Get the status of commands to offline devices.
Request
To get the status of commands to offline devices, you make a GET
request to the ` /v1/datastore/queue` resource.
Request path and header example
GET /v1/datastore/queue/<queuedResultId>?maxResults={maxResults}&nextToken={nextToken}
Content-Type: application/json
Authorization: Bearer {access_token}
Request path and header parameters
Parameter | Located in | Description | Type | Required |
---|---|---|---|---|
|
Path |
Unique identifier to query for queued delivery for offline devices. Retrieve this identifier from the response from the Commands operation. |
String |
Yes |
|
Query |
Maximum number of results to return in the response. |
Integer |
No |
|
Query |
Identifies the next set of data to return. Use the |
String |
No |
|
Header |
Access token for your skill. Use your client credentials and the scope to obtain the access token. For details, see Authentication. |
String |
Yes |
Request body example
The request has no body
Request body properties
The request has no body
Response
A successful response returns HTTP 200 OK
, along with a list of command results for queued commands. An empty response means that all targeted devices received the commands.
On error, the response returns the appropriate HTTP status code and includes a response body with an Error object.
Response body example
{
"items": [
{
"deviceId": "amzn1.ask.device.2",
"type": "DEVICE_UNAVAILABLE",
"message": "AOGS: Send directive failure: Device unreachable"
},
{
"deviceId": "amzn1.ask.device.3",
"type": "DEVICE_UNAVAILABLE",
"message": "AOGS: Send directive failure: Device unreachable"
}
],
"paginationContext": {
"totalCount": 227,
"nextToken": "someToken.13",
"previousToken": "someToken.1"
}
}
Response body properties
Property | Description | Type |
---|---|---|
|
Unordered list of dispatch results. Contains results from the earlier |
Array of objects |
|
ID of a device that Alexa was unable to update. |
String |
|
Indicates the result of the attempt to update the device.
|
String |
|
Message that describes the error. |
String |
|
(Optional) Indicates whether there are more results to return. |
Object |
|
Total number of results at the time of current response. |
Integer |
|
Token for the previous page of results. Not provided when the request returns the first page of results. |
String |
|
Included when the response is truncated. Use this value in a subsequent request. Not provided when the request returns the last page of results. |
String |
HTTP status codes
Status | Description |
---|---|
|
Response body contains the results in the |
|
Indicates that one or more properties in the request body aren't valid.
|
|
Request didn't include the authorization token, or the included token expired or isn't valid. Or, you don't have access to the resource.
|
|
Indicates that the authorization token is valid, but the requested operation isn't allowed.
|
|
Permitted rate limit, specified as number of requests per unit of time, exceeded. Retry the request by using exponential back-off. |
|
Error occurred on the server. Retry the request by using exponential back-off.
|
Object definitions
The Data Store API defines the following objects.
Data store commands
Use the following data store commands to add or remove data for the specified namespace for the specified devices. You call the Commands operation to run these commands.
PUT_NAMESPACE
Creates a new namespace in the region with the provided namespace
name. Ignored if the namespace
already exists in the region.
Property | Description | Type | Required |
---|---|---|---|
|
Type of command to run. Set to |
String |
Yes |
|
Identifier for the namespace to create. Must be unique within the region for your skill. The namespace must be a be a non-empty string that meets the follow requirements:
The |
String |
Yes |
PUT_OBJECT
Creates or updates the object provided in content
to the specified key
within the specified namespace
. If the specified namespace
doesn't exist in the region, this command creates the namespace.
If the specified key
contains an existing object, the PUT_OBJECT
command overwrites the existing object. If the specified key
contains an existing array, the PUT_OBJECT
command replaces the array in the data store with the array provided in the command. The command doesn't attempt to merge the two arrays.
Property | Description | Type | Required |
---|---|---|---|
|
Type of command to run. Set to |
String |
Yes |
|
Unique identifier for the namespace to update with the provided
The |
String |
Yes |
|
Unique identifier for the object to update with the provided
The |
String |
Yes |
|
Content to add or update at the specified |
|
Yes |
Example: update an object in the data store
The following example shows an APL document that configures the data store to store an object at the key called mainPage
. The dataType
is OBJECT
. For details about the data store settings in a document, see APL Data Store Extension.
{
"type": "APL",
"version": "2024.3",
"extensions": [
{
"uri": "alexaext:datastore:10",
"name": "DataStore"
}
],
"settings": {
"DataStore": {
"dataBindings": [
{
"namespace": "objectDataStoreExample",
"key": "mainPage",
"dataBindingName": "dsMainPage",
"dataType": "OBJECT"
}
]
}
},
"mainTemplate": {}
}
To update the object at the mainPage
key, use the following PUT_OBJECT
command. The content
property in the command must contain an object because the dataType
of the data stored at this key is OBJECT
. In this example, the new object for the mainPage
key has four properties.
{
"type": "PUT_OBJECT",
"namespace": "objectDataStoreExample",
"key": "mainPage",
"content": {
"headerTitle": "This is the header title from the data store",
"primaryText": "This is the primaryText from the data store",
"secondaryText": "Secondary text from the data store",
"tertiaryText": "Tertiary text from the data store"
}
}
Example: Update an array in the data store
The following example shows an APL document that configures the data store to store an array at the key called mainList
. The dataType
is ARRAY
. For details about the data store settings in a document, see APL Data Store Extension.
{
"type": "APL",
"version": "2024.3",
"extensions": [
{
"uri": "alexaext:datastore:10",
"name": "DataStore"
}
],
"settings": {
"DataStore": {
"dataBindings": [
{
"namespace": "arrayDataStoreExample",
"key": "mainList",
"dataBindingName": "dsListItemsToShow",
"dataType": "ARRAY"
}
]
}
},
"mainTemplate": {}
}
To update the array at the mainList
key, use the following PUT_OBJECT
command. Note that the content
property in the command must contain an array because the dataType
of the data stored at this key is ARRAY
. In this example, the new array for the mainList
key contains four items.
{
"type": "PUT_OBJECT",
"namespace": "arrayDataStoreExample",
"key": "mainList",
"content": [
{
"primaryText": "The first list item."
},
{
"primaryText": "The second list item."
},
{
"primaryText": "The third list item."
},
{
"primaryText": "The fourth list item."
}
]
}
REMOVE_NAMESPACE
Deletes the specified namespace
from the region. Ignored if the provided namespace
doesn't exist.
Property | Description | Type | Required |
---|---|---|---|
|
Type of command to run. Set to |
String |
Yes |
|
Identifier for the namespace to remove. |
String |
Yes |
REMOVE_OBJECT
Deletes the object stored at the specified namespace
and key
. Ignored if the object doesn't exist.
Property | Description | Type | Required |
---|---|---|---|
|
Type of command to run. Set to |
String |
Yes |
|
Unique identifier for the namespace that contains the object to remove. Must be unique within the region for your skill. The namespace must be a be a non-empty string that meets the follow requirements:
The |
String |
Yes |
|
Unique identifier for the object to remove. The key must be a non-empty string that meets the following requirements:
The |
String |
Yes |
CLEAR
Deletes the region for your skill. Ignored if your skill doesn't have a region on the device.
Deleting a region deletes all namespaces
and objects stored within that region. Data stored in the region isn't recoverable. The next PUT_NAMESPACE
or PUT_OBJECT
command recreates the region with the data specified in those commands, but doesn't restore any of the deleted data.
Property | Description | Type | Required |
---|---|---|---|
|
Type of command to run. Set to |
String |
Yes |
Error object
The Error
object defines the error type and message included in the response when an error occurs.
The following example shows the response body.
{
"type": "BAD_REQUEST",
"message": "The request is malformed or is missing any required parameters."
}
Property | Description | Type |
---|---|---|
|
Type of error that occurred. |
String |
|
Human-readable error message. The error message appears only for debugging and logging purposes. You must not share it with the customer. No business logic should depend on the content of the error message. |
String |
Target object
The Target
object specifies either a list of device ID values or a single user ID. Use the target in the Commands
operation. The following list shows the criteria to publish your updates to devices.
- To publish your updates to a device or a group of devices, set the target
type
toDEVICES
and provide an array of up to 20 device IDs in theitems
property. The commands you provide run on each specified device. - To publish your updates to the devices associated with a specific user, set the target
type
toUSER
and provide a single user ID in theitem
property. The commands you provide run on each device associated with that user. The operation skips any devices that don't support the data store.
Every request sent to your skill includes properties for deviceId
and userId
in the context.System.user.userId
and context.System.device.deviceId
properties. Retrieve these values from the UsagesInstalled
request that your skill receives when a user chooses to install your widget and save them in persistent storage to use with the Data Store REST API. These values are unique to your skill. You can't use the deviceId
or userId
from one skill with a different skill.
For details about the user and device IDs in the skill request, see the System object.
Property | Description | Type | Required |
---|---|---|---|
|
Type of target for the commands. |
Enumeration |
Yes |
|
List of device IDs representing the devices to update. Set to one or more |
Array of strings |
Yes when |
|
User ID. Set to |
String |
Yes when |
Sample code
The following sample code demonstrates how to build a basic widget and update the on-device data store by using the Data Store API.
Related topics
- About Widgets and Alexa Presentation Language (APL)
- Alexa.DataStore.PackageManager Interface Reference
Last updated: Nov 26, 2024