REST APIs
- Topics:
- Developing Screens
CREATED FOR:
- Intermediate
- Developer
AEM Screens provides a simple RESTful API that follows the Siren specification. It lets you navigate the content structure and send commands to devices in the environment.
The API is accessible at http://localhost:4502/api/screens.json.
Navigating Content Structure
The JSON returned by the API calls lists the entities related to the current resource. Following the listed self-link, each of these entities is again accessible as a REST resource.
For instance, to access the displays in the demo flagship location, you can call the following:
GET /api/screens/content/screens/we-retail/locations/demo/flagship.json HTTP/1.1
Host: http://localhost:4502
Or using curl:
curl -u admin:admin http://localhost:4502/api/screens/content/screens/we-retail/locations/demo/flagship.json
The result would look like:
{
"class": [
"aem-io/screens/location"
],
"links": [
{
"rel": [
"self"
],
"href": "http://localhost:4502/api/screens/content/screens/we-retail/locations/demo/flagship.json"
},
{
"rel": [
"parent"
],
"href": "http://localhost:4502/api/screens/content/screens/we-retail/locations/demo.json"
}
],
"properties": {…},
"entities": [
{
"class": [
"aem-io/screens/display"
],
"links": [
{
"rel": [
"self"
],
"href": "http://localhost:4502/api/screens/content/screens/we-retail/locations/demo/flagship/single.json"
}
],
"rel": [
"child"
],
"properties": {
"title": "Single Screen Display",
"height": 1440,
"description": "Demo location of a single screen display.",
"name": "single",
"width": 2560,
"idletimeout": 300,
"layoutrows": 1,
"layoutcols": 1
}
},
…
]
}
And then to access the Single Screen Display, you can call:
GET /api/screens/content/screens/we-retail/locations/demo/flagship/single.json HTTP/1.1
Host: http://localhost:4502
Executing Actions on the Resource
The JSON returned by the API calls can contain a list of actions that are available on the resource.
The display, for instance, lists a broadcast-command action that allows to send a command to all the devices assigned to that display.
GET /api/screens/content/screens/we-retail/locations/demo/flagship/single.json HTTP/1.1
Host: http://localhost:4502
Or using curl:
curl -u admin:admin http://localhost:4502/api/screens/content/screens/we-retail/locations/demo/flagship/single.json
Result:
{
"class": [
"aem-io/screens/display"
],
"links": […],
"properties": {…},
"entities": […],
"actions": [
{
"title": "",
"name": "broadcast-command",
"method": "POST",
"href": "/api/screens/content/screens/we-retail/locations/demo/flagship/single",
"fields": [
{
"name": ":operation",
"value": "broadcast-command",
"type": "hidden"
},
{
"name": "msg",
"type": "text"
}
]
}
]
}
To trigger this action, call the following:
POST /api/screens/content/screens/we-retail/locations/demo/flagship/single.json HTTP/1.1
Host: http://localhost:4502
:operation=broadcast-command&msg=reboot
Or using curl:
curl -u admin:admin -X POST -d ':operation=broadcast-command&msg=reboot' http://localhost:4502/api/screens/content/screens/we-retail/locations/demo/flagship/single.json