Data Store REST API Reference
The Data Store REST API provides operations to update the data store on a device. Use this API to 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.
The API 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).
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
You call the API with a POST request.
Authentication
You must authenticate your skill with Alexa and retrieve an access token to call the Data Store API. Pass the access token to the API call in the header.
To authenticate your skill and retrieve the access token, complete the following steps:
- Obtain the client ID and client secret credentials for your skill.
- Use the credentials to call the token endpoint and retrieve an access token.
Obtain the client ID and client secret values
You can use the Alexa Skills Kit (ASK) Command Line Interface (CLI) or the developer console to retrieve these values for your skill.
To get the credentials with the ASK CLI
- At the command prompt, enter the syntax for the
get-skill-credentials
command.
To get the credentials in the developer console
- Sign in to the Alexa developer console, and then open the skill.
- In the sidebar, select Tools > Permissions.
- Scroll to the bottom of the page, and then copy the value from the Alexa Client ID field.
- Click SHOW, and then copy the value from the Alexa Client Secret field.
Use the credentials to retrieve an access token
To get the access token, make a POST call to https://api.amazon.com/auth/o2/token
. Access tokens expire. Therefore, your code that calls the Data Store API must retrieve a new token if the previous one has already expired.
To get the access token
- Make a POST call to
https://api.amazon.com/auth/o2/token
. -
Set the body of the request to the following syntax, replacing
{SkillClientId}
and{SkillClientSecret}
with the client ID and client secret for your skill.grant_type=client_credentials&client_id={SkillClientId}&client_secret={SkillClientSecret}&scope=alexa::datastore
The token endpoint returns a JSON object with the field
access_token
. - Pass the
access_token
value to theAuthorization
header in your calls to the Data Store API.
The following example shows a curl command that retrieves the access token.
curl --location --request POST 'https://api.amazon.com/auth/o2/token' \
--header 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' \
--data-raw 'grant_type=client_credentials&client_id={SkillClientId}&client_secret={SkillClientSecret}&scope=alexa::datastore'
The following example shows a response from the token endpoint. In this example, the token expires in 3600 seconds, which is one hour.
{
"access_token": "<access-token-string>",
"scope": "alexa::datastore",
"token_type": "bearer",
"expires_in": 3600
}
Operations
The Data Store API includes the following operations.
Operation | HTTP method and URI |
---|---|
| |
| |
|
Commands
Runs the provided set of commands to update the data store for a specified list of devices or users. For details about the commands you can run, see Data store commands, later.
Request
To run the set of commands to update the data store, you make a POST request.
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 token endpoint 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": "{ISO-8601 Date/time}"
}
Request body properties
Property | Description | Type | Required |
---|---|---|---|
|
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 |
|
An object that identifies the target for the commands. This object can represent a list of device IDs or a user ID. For details, see Command target. |
Target object |
Yes |
|
Type of target for the commands. Allowed values: |
Enumeration |
Yes |
|
Applies when |
Array of strings |
Yes when |
|
Applies when |
String |
Yes when |
|
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. |
Timestamp in ISO-8601 format |
No |
Command target
The Commands operation requires a target
object that specifies either a list of device ID values or a single user ID. 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.
Response
A successful response returns HTTP 200 OK, and an object that provides the results for each device. On error, the response returns an HTTP status code that includes a response body with an error code and message.
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 |
---|---|---|
|
Array of dispatch result objects containing the results of the call for each target user or device. Each object in this array indicates whether the operation was successful for the device. The items in the
|
Array |
|
The ID of a device that Alexa attempted to update. |
String |
|
Value that indicates the result of the attempt to update the device.
|
Enumeration |
|
Message that describes the error. |
String |
|
Applies when at least one device was offline ( Not provided when no devices in the request were offline. |
String |
HTTP status codes
If the API returns any status other than 200
, this means that 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 |
|
The request validation failed. Possible errors:
|
|
|
|
|
|
|
|
|
Queued result query
Query the status of command deliveries to offline devices.
Request
To get the status of deliveries to offline devices, you make a GET request.
Request path and header example
GET /v1/datastore/queue/<queuedResultId>?maxResults={INTEGER}&nextToken={STRING}
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 token endpoint to obtain the access token. For details, see Authentication. |
String |
Yes |
|
Path |
A unique identifier that identifies the request with offline devices. Retrieve this identifier from the dispatch results object returned from the commands operation. |
String |
Yes |
|
Query |
Maximum number of dispatch result items to return in each page. Defaults to 20. Use the |
Integer |
No |
|
Query |
The value of |
String |
No |
Request body example
The request has no body
Request body properties
The request has no body
Response
A successful response returns HTTP 200 OK, and an object that provides an array of dispatch results that weren't delivered. On error, the response returns an HTTP status code that includes a response body with an error code and message.
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": "token-for-next-page",
"previousToken": "token-for-previous-page"
}
}
Response body properties
Property | Description | Type |
---|---|---|
|
Unordered array of dispatch result objects. Contains results from the earlier commands request in which the operation was unsuccessful. This means any results where the |
Array |
|
The ID of a device that Alexa was unable to update. |
String |
|
Value that indicates the result of the attempt to update the device.
|
Enumeration |
|
Message that describes the error. |
String |
|
An object containing pagination details when the query returns many items. Use the properties of this object to paginate through the results. |
Object |
|
The total number of results at the time of current response. |
Integer |
|
The token for the previous page of results. Not provided when the request returns the initial page of results. |
String |
|
The token for the next page of results. Not provided when the request returns the last page of results. |
String |
HTTP status codes
If the API returns any status other than 200
, this means that the API call failed.
Status | Description |
---|---|
|
The call was successful. See the response body for the results provided in the |
|
The request validation failed. Possible errors:
|
|
|
|
|
|
|
|
|
Cancel
Cancels a pending request for a specified queued result.
Request
To get cancel a pending request, you make a POST request.
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 |
---|---|---|---|---|
|
Header |
Access token for your skill. Use your client credentials and the token endpoint to obtain the access token. For details, see Authentication. |
String |
Yes |
|
Path |
A unique identifier that identifies the request with pending updates. Retrieve this identifier from the dispatch results object returned from the commands operation. |
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 with no response body.
Response body example
The response has no body for a successful result.
Response body properties
The response has no body for a successful result.
HTTP status codes
If the API returns any status other than 204 No Content
, this means that the API call failed. The body of the request contains an object with the type
and message
for the error.
Status | Description |
---|---|
|
The call was successful and the pending request has been canceled. |
|
The request validation failed. Possible errors:
|
|
|
|
|
|
|
|
|
|
|
Data store commands
Use the Commands operation to run these commands.
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 REST API automatically determines the region for your skill based on the skill ID. Your skill can't access the data store for any other skills.
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.
PUT_NAMESPACE
Creates new namespace in the region with the provided namespace
name. Ignored if the namespace
already exists in the region.
Command properties
Property | Type | Required | Description |
---|---|---|---|
|
|
Yes |
Type of command to run. Set to |
|
|
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 |
PUT_OBJECT
Adds the object provided in content
to the specified key
within the specified namespace
. This command creates the namespace if the specified namespace
doesn't exist in the region.
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.
Command properties
Property | Type | Required | Description |
---|---|---|---|
|
|
Yes |
Type of command to run. Set to |
|
|
Yes |
Unique identifier for the namespace to update with the provided
The |
|
|
Yes |
Unique identifier for the object to update with the provided
The |
|
|
Yes |
The content to add or update at the specified |
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 set to OBJECT
. For details about the data store settings in a document, see APL Data Store Extension.
{
"type": "APL",
"version": "2024.2",
"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. Note that 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 set to ARRAY
. For details about the data store settings in a document, see APL Data Store Extension.
{
"type": "APL",
"version": "2024.2",
"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.
Command parameters
Property | Type | Required | Description |
---|---|---|---|
|
|
Yes |
Type of command to run. Set to |
|
|
Yes |
Identifier for the namespace to remove. |
REMOVE_OBJECT
Deletes the object stored at the specified namespace
and key
. Ignored if the object doesn't exist.
Command properties
Property | Type | Required | Description |
---|---|---|---|
|
|
Yes |
Type of command to run. Set to |
|
|
Yes |
Unique identifier for the namespace that contains the object to remove. |
|
|
Yes |
Unique identifier for the object to remove. |
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.
Command properties
Property | Type | Required | Description |
---|---|---|---|
|
|
Yes |
Type of command to run. Set to |
Related topics
- About Widgets and Alexa Presentation Language (APL)
- Alexa.DataStore.PackageManager Interface Reference
Last updated: Nov 03, 2023