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 and key 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

POST /v1/datastore/queue/<queuedResultId>/cancel

Commands

POST /v1/datastore/commands

Queued result query

GET /v1/datastore/queue/<queuedResultId>?maxResults={maxResults}&nextToken={nextToken}

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

Copied to clipboard.

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

queuedResultId

Path

Unique identifier to query for queued delivery for offline devices. Retrieve this identifier from the response from the Commands operation.

String

Yes

access_token

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

204 No Content

Pending request successfully canceled.

400 Bad Request

Indicates that one or more properties in the request body aren't valid.

The response might include one of the following errors types and messages:

  • COMMANDS_DELIVERED – The pending commands have been delivered.
  • CONCURRENCY_ERROR – There are concurrent attempts to deliver the pending commands.

401 Unauthorized

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.

The response might include one of the following errors types and messages:

  • INVALID_ACCESS_TOKEN – Access token is expired or invalid.

403 Forbidden

Indicates that the authorization token is valid, but the requested operation isn't allowed.

The response might include one of the following errors types and messages:

  • DATA_STORE_SUPPORT_REQUIRED – The skill isn't configured with support for the Alexa.DataStore interface.
    Update your skill to support the required interfaces. For details, see Enable the interfaces for widgets

429 Too many requests

Permitted rate limit, specified as number of requests per unit of time, exceeded. Retry the request by using exponential back-off.

500

Error occurred on the server. Retry the request by using exponential back-off.

The response might include one of the following errors types and messages:

  • DATASTORE_UNAVAILABLE – An unexpected internal service error occurred.

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

Copied to clipboard.

POST /v1/datastore/commands
Content-Type: application/json
Authorization: Bearer {access_token} 

Request path and header parameters

Parameter Located in Description Type Required

access_token

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

Copied to clipboard.

{
  "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

commands

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

target

Identifies the target for the commands. Include either a list of device IDs or one user ID.

Target object

Yes

attemptDeliveryUntil

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 dispatchResults in the response body to determine whether any devices in the request were unreachable.
Defined in ISO 8601 format, YYYY-MM-DDThh:mm:ssZ.

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

results

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 results array depend on the type of target in the request.

  • DEVICES: the number and order of items in the results array is the same as the order of the device IDs in the target.items array.
  • USER: the number and order of items in the results array depends on the number of devices associated with the specified user and therefore can vary.

Array of objects

results[].deviceId

ID of the device that Alexa attempted to update.
Formatted as an Amazon Common Identifier (ACI), amzn1.ask.device.{id}.

String

results[].type

Formatted as an Amazon Common Identifier (ACI), amzn1.ask.device.{id}.

  • SUCCESS – The target device received the payload.
  • INVALID_DEVICE – The target device isn't capable of processing the payload. For example, the target device doesn't support the data store.
  • DEVICE_UNAVAILABLE – The dispatch failed because the device is offline. When the commands operation sets the attemptDeliveryUntil property, Alexa attempts to redeliver the commands when the device is back online. You can use the query operation to get the status of this attempted delivery.
  • DEVICE_PERMANENTLY_UNAVAILABLE – The dispatch failed because the device is no longer available. For example, this error occurs when the target device is no longer registered.
  • CONCURRENCY_ERROR – There were multiple, concurrent attempts to update the same data store region. You can use the query operation to get the status of the attempted delivery before you attempt to send a new commands request.
  • INTERNAL_ERROR – The dispatch failed because of an unknown error.
  • PENDING_REQUEST_COUNT_EXCEEDS_LIMIT – The count of pending requests exceeds the limit.

String

results[].message

(Optional) Message that describes the error.

String

queuedResultId

(Optional) Applies when at least one device was offline (DEVICE_UNAVAILABLE). Use this identifier with the query operation to determine the status of the attempts to redeliver the command. The result is available for query until at least one hour after the attemptDeliveryUntil time specified in the request..

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

200 OK

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 results array. This response doesn't mean that every device received the commands payload. Inspect the response body to determine the results for each device. For details about the results array, see Response body properties.

400 Bad Request

Indicates that one or more properties in the request body aren't valid.

The response might include one of the following errors types and messages:

  • COMMANDS_PAYLOAD_EXCEEDS_LIMIT – The total size of commands can't exceed 16Kb in UTF-encoding.
  • NO_TARGET_DEFINED – No target device is defined. Applies when target.type is DEVICES.
  • TOO_MANY_TARGETS – Number of targets in the request exceeds the limits of 20 devices values or one user ID.
  • INVALID_REQUEST – Request payload doesn't comply with the JSON schema, or a command violates a field restriction.

401 Unauthorized

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.

The response might include one of the following errors types and messages:

  • INVALID_ACCESS_TOKEN – Access token is expired or invalid.

403 Forbidden

Indicates that the authorization token is valid, but the requested operation isn't allowed.

The response might include one of the following errors types and messages:

  • DATA_STORE_SUPPORT_REQUIRED – The skill isn't configured with support for the Alexa.DataStore interface.
    Update your skill to support the required interfaces. For details, see Enable the interfaces for widgets

429 Too many requests

Permitted rate limit, specified as number of requests per unit of time, exceeded. Retry the request by using exponential back-off.

500

Error occurred on the server. Retry the request by using exponential back-off.

The response might include one of the following errors types and messages:

  • DATASTORE_UNAVAILABLE – An unexpected internal service error occurred.

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

Copied to clipboard.

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

queuedResultId

Path

Unique identifier to query for queued delivery for offline devices. Retrieve this identifier from the response from the Commands operation.

String

Yes

maxResults

Query

Maximum number of results to return in the response.
Valid values: 1–100. Default: 20.

Integer

No

nextToken

Query

Identifies the next set of data to return. Use the paginationContext.nextToken property from a previous response. Include if iterating over a paginated response. If not included, the response includes the first page of results.

String

No

access_token

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

items

Unordered list of dispatch results. Contains results from the earlier commands request in which the operation was unsuccessful. This means any results where the type wasn't SUCCESS.

Array of objects

items[].deviceId

ID of a device that Alexa was unable to update.
Formatted as an Amazon Common Identifier (ACI), amzn1.ask.device.{id}.

String

items[].type

Indicates the result of the attempt to update the device.
Valid values:

  • DEVICE_UNAVAILABLE – Alexa continues to attempt to deliver the commands to the device until the current time exceeds the attemptDeliveryUntil time.
  • DEVICE_PERMANENTLY_UNAVAILABLE – Delivery attempts to this device are stopped. Your skill should stop attempting to push updates to the device.
  • CONCURRENCY_ERROR – There were multiple, concurrent attempts to update the same data store region.

String

items[].message

Message that describes the error.

String

paginationContext

(Optional) Indicates whether there are more results to return.

Object

paginationContext.totalCount

Total number of results at the time of current response.

Integer

paginationContext.previousToken

Token for the previous page of results. Not provided when the request returns the first page of results.

String

paginationContext.nextToken

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

200 OK

Response body contains the results in the items array. For details, see Response body properties.

400 Bad Request

Indicates that one or more properties in the request body aren't valid.

The response might include one of the following errors types and messages:

  • INVALID_REQUEST – Request payload doesn't comply with the JSON schema, or a command violates a field restriction.

401 Unauthorized

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.

The response might include one of the following errors types and messages:

  • INVALID_ACCESS_TOKEN – Access token is expired or invalid.

403 Forbidden

Indicates that the authorization token is valid, but the requested operation isn't allowed.

The response might include one of the following errors types and messages:

  • DATA_STORE_SUPPORT_REQUIRED – The skill isn't configured with support for the Alexa.DataStore interface.
    Update your skill to support the required interfaces. For details, see Enable the interfaces for widgets

429 Too many requests

Permitted rate limit, specified as number of requests per unit of time, exceeded. Retry the request by using exponential back-off.

500

Error occurred on the server. Retry the request by using exponential back-off.

The response might include one of the following errors types and messages:

  • DATASTORE_UNAVAILABLE – An unexpected internal service error occurred.

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

Type of command to run. Set to PUT_NAMESPACE.

String

Yes

namespace

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:

  • Fewer than 512 bytes
  • Doesn't begin with the string "sqlite_"
  • Doesn't match any SQLite reserved keywords
  • Doesn't start with an underscore (_)
  • Allowed character set: [_ - . a-z A-Z 0-9]

The namespace name contributes to the data store storage allocated to your skill. For details about limits, see Data store limits.

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

Type of command to run. Set to PUT_OBJECT.

String

Yes

namespace

Unique identifier for the namespace to update with the provided content. Must be unique within the region for your skill. The namespace must be a be a non-empty string that meets the follow requirements:

  • Fewer than 512 bytes
  • Doesn't begin with the string "sqlite_"
  • Doesn't match any SQLite reserved keywords
  • Doesn't start with an underscore (_)
  • Allowed character set: [_ - . a-z A-Z 0-9]

The namespace name contributes to the data store storage allocated to your skill. For details about limits, see Data store limits.

String

Yes

key

Unique identifier for the object to update with the provided content. The key must be a non-empty string that meets the following requirements:

  • Fewer than 512 bytes
  • Doesn't start with an underscore (_)
  • Allowed character set: [_ - . a-z A-Z 0-9]

The key name contributes to the data store storage allocated to your skill. For details about limits, see Data store limits.

String

Yes

content

Content to add or update at the specified namespace and key. The PUT_OBJECT command doesn't inspect or validate this payload.

Make sure that the data you provide in this property matches the dataType defined for the specified namespace and key. For example, if you configured the data store extension to store an ARRAY at a specified namespace and key, you must provide an ARRAY in the content property of the PUT_OBJECT command. For examples, see Example: update an object in the data store and Example: Update an array in the data store.

Object or Array

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.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. 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.

Copied to clipboard.

{
  "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.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.

Copied to clipboard.

{
  "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

Type of command to run. Set to REMOVE_NAMESPACE.

String

Yes

namespace

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

Type of command to run. Set to REMOVE_OBJECT.

String

Yes

namespace

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:

  • Fewer than 512 bytes
  • Doesn't begin with the string "sqlite_"
  • Doesn't match any SQLite reserved keywords
  • Doesn't start with an underscore (_)
  • Allowed character set: [_ - . a-z A-Z 0-9]

The namespace name contributes to the data store storage allocated to your skill. For details about limits, see Data store limits.

String

Yes

key

Unique identifier for the object to remove. The key must be a non-empty string that meets the following requirements:

  • Fewer than 512 bytes
  • Doesn't start with an underscore (_)
  • Allowed character set: [_ - . a-z A-Z 0-9]

The key name contributes to the data store storage allocated to your skill. For details about limits, see Data store limits.

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

Type of command to run. Set to CLEAR.

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

Type of error that occurred.
For specific error types, see the HTTP status code table for each operation.

String

message

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 to DEVICES and provide an array of up to 20 device IDs in the items 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 to USER and provide a single user ID in the item 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

target.type

Type of target for the commands.
Valid values: DEVICES, USER.

Enumeration

Yes

target.items

List of device IDs representing the devices to update. Set to one or more context.System.device.deviceId values from previous UsagesInstalled requests.
The operation runs the commands on each specified device. Include when type is DEVICES.
Maximum size: 20.

Array of strings

Yes when type is DEVICES

target.id

User ID. Set to context.System.user.userId from a UsagesInstalled request.
The operation runs the commands on each device associated with the user. Include when type is USER.

String

Yes when type is USER.

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.


Was this page helpful?

Last updated: Nov 26, 2024