You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: API/README.md
+32-28Lines changed: 32 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
##MagicMirror Remote Control API
1
+
# MagicMirror² Remote Control API
2
2
3
3
## Introduction
4
4
5
-
The MMM-Remote-Control Module for MagicMirror² implements a RESTful(-ish) API to control the Magic Mirror using the existing functionality built-in to MMM-Remote-Control, as well as the notifications commands built into most modules. In addition, the API creates a basic framework which allows for each module to expand or customize their own API by a simple notificiation.
5
+
The MMM-Remote-Control Module for MagicMirror² implements a RESTful(-ish) API to control the MagicMirror² using the existing functionality built-in to MMM-Remote-Control, as well as the notifications commands built into most modules. In addition, the API creates a basic framework which allows for each module to expand or customize their own API by a simple notificiation.
6
6
7
7
This expansion was developed by [shbatm](https://github.com/shbatm) using [juzim's MMM-Api](https://github.com/juzim/MMM-Api) and of-course, [jopyth's MMM-Remote-Control](https://github.com/jopyth/MMM-Remote-Control).
8
8
@@ -17,30 +17,30 @@ All URLs will be of the form: `http://magicmirrorip:8080/api/{your command}` and
17
17
### Basic examples for showing an Alert on the screen
18
18
19
19
```bash
20
-
$ curl -X GET http://magicmirrorip:8080/api/module/alert/showalert?message=Hello&timer=2000
20
+
curl -X GET http://magicmirrorip:8080/api/module/alert/showalert?message=Hello&timer=2000
21
21
```
22
22
23
23
```bash
24
24
$ curl -X POST http://magicmirrorip:8080/api/module/alert/showalert \
25
25
-H 'content-type: application/json' \
26
-
-d '{
27
-
"title": "Hello World!",
28
-
"message": "Alert Successfully Shown!",
26
+
-d '{
27
+
"title": "Hello World!",
28
+
"message": "Alert Successfully Shown!",
29
29
"timer": 2000
30
30
}'
31
31
```
32
32
33
33
### Basic examples of sending a Module Notification
34
34
35
35
```bash
36
-
$ curl -X GET http://magicmirrorip:8080/api/notification/HELLO_WORLD
36
+
curl -X GET http://magicmirrorip:8080/api/notification/HELLO_WORLD
37
37
```
38
38
39
39
```bash
40
40
$ curl -X POST http://magicmirrorip:8080/api/notification/HELLO_WORLD \
41
41
-H 'content-type: application/json' \
42
-
-d '{
43
-
"mypayload": "Hello World!",
42
+
-d '{
43
+
"mypayload": "Hello World!",
44
44
"somthingelse": "Wooo!"
45
45
}'
46
46
```
@@ -52,6 +52,7 @@ Providing an API key is recommended; however, remains optional. If you wish to u
52
52
If you ran the `installer.sh` script when you installed the module, a non-canoical UUID is generated for you to use; you can use this unique code, or use any string you wish.
53
53
54
54
### Example Config Section
55
+
55
56
```js
56
57
{
57
58
module:'MMM-Remote-Control'
@@ -64,25 +65,28 @@ If you ran the `installer.sh` script when you installed the module, a non-canoic
64
65
### Passing your API key
65
66
66
67
The API Key can be passed in one of two ways, either as part of the query string at the end of the URL:
68
+
67
69
```bash
68
-
$ curl -X GET http://magicmirrorip:8080/api/module/alert/showalert?message=Hello&timer=2000&apiKey=bc2e979db92f4741afad01d5d18eb8e2
70
+
curl -X GET http://magicmirrorip:8080/api/module/alert/showalert?message=Hello&timer=2000&apiKey=bc2e979db92f4741afad01d5d18eb8e2
69
71
```
70
72
71
73
It can also be passed as an Authorization Header:
74
+
72
75
```bash
73
76
$ curl -X POST http://magicmirrorip:8080/api/module/alert/showalert \
***For convenience, the remainder of the examples omit the API Key***
84
87
85
88
## Secure Endpoints
89
+
86
90
Since 2.2.0, and in a way to prevent malicious actions on your mirror, a new config was added. This config allow you to, in case you don't use an apikey or never use the API at all, prevent some endpoints to work without an apikey.
87
91
As usual, this option can be disabled, but this will expose your Mirror to potentials hackers, so it's up to you to turn it off.
88
92
@@ -105,7 +109,7 @@ There are three general categories of API commands:
105
109
**1. MMM-Remote-Control Internal Commands** -- these are used to call the existing commands that MMM-Remote-Control already exposes. For example, to turn off the monitor ("MONITOROFF"):
106
110
107
111
```bash
108
-
$ curl -X GET http://magicmirrorip:8080/api/monitor/off
112
+
curl -X GET http://magicmirrorip:8080/api/monitor/off
109
113
```
110
114
111
115
**2. External APIs (Guessed)** -- when this module first loads, it parses all of the installed modules' source code and checks for any custom notifications that are used. From this basic search, it tries to "guess" notification actions that may be valid, without them being explicitly defined anywhere else. For example, the "alert" command examples above are not defined within this module, the 'alert' module just looks for a notification, "SHOW_ALERT"--this is exposed as a `/module/alert/showalert` action in the External API processor. Full credit to this idea goes to `juzim` from the MMM-Api module.
@@ -118,7 +122,7 @@ The majority of MMM-Remote-Control's abilities are extended to the API (this is
118
122
119
123
Review the API documentation online [here](https://ezeholz.github.io/MMM-Remote-Control/)
120
124
121
-
Or check it in your own installation using http://ip-of-your-mirror:8080/api/docs
125
+
Or check it in your own installation using <http://ip-of-your-mirror:8080/api/docs>
122
126
123
127
### 2. External APIs (Guessed)
124
128
@@ -131,13 +135,13 @@ As discussed above, these methods are guessed based on your currently installed
131
135
132
136
-*NOTE:* Just because an action appears in this list, does not necessarily mean it is valid and the related module will do what you want. Consult each modules' README for details on what notifications can be used and how.
133
137
134
-
#### Example:
138
+
#### Example
135
139
136
140
```bash
137
-
$ curl -X GET http://magicmirrorip:8080/api/module/newsfeed
141
+
curl -X GET http://magicmirrorip:8080/api/module/newsfeed
138
142
```
139
143
140
-
#### Returns:
144
+
#### Returns
141
145
142
146
```json
143
147
{
@@ -187,17 +191,17 @@ If correctly formated, any details sent here will override the "guessed" action
| `prettyName` | *Optional:* You can specify a Formatted Name to use in dynamic menus, like the MMM-Remote-Control Module Control menu, otherwise one will be guessed based on the Notification text.
217
221
| `payload` | *Optional:* If you always want the module to send the same `payload`, you can provide an `Object` here. It will be merged into the `payload` sent with the notification, which will also include:<br>1. URL Parameter, if used. See notes on `payload` Object below.<br>2. Query String, if used. API key will be removed.<br>3. Request body, if `POST` method is used and a body sent.<br>4. Finally, this parameter.
218
222
219
-
#### About the `payload` Object
223
+
#### About the `payload` Object
220
224
221
225
Your module will be sent a `payload` with the notification, depending on the request details, and if you provided a `payload` Object to send. It is a merged object, containing one or more of the following inputs.
0 commit comments