API: Commands

From Yombo
Jump to: navigation, search

Summary

Commands are used to control devices. Commands can be added as needed to support additional device types.

GET - All commands

Retrieve all commands available to the current user. This includes public commands and private commands specific to the user.

Request URL

  • GET https://api.yombo.net/api/v1/commands

Parameters

None

Example

  <div id="curl<random_number></random_number>" class="tab-pane fade in active" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
curl \
-H "x-api-key: abc123xyz789" \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...." \
-H "Accept: application/json" \
/api/v1/commands?page[size]=3
  <div id="python<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
import requests

url = 'https://api.yombo.net/api/v1/commands?page[size]=3'
headers = {
    'x-api-key': 'abc123xyz789',
    'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJ...',
    'Accept': 'application/json',  # demo, this is the default
    }
response = requests.get(url, headers=headers)
the_data = response.json()  # create a dictionary from results
  <div id="output<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
 1 {
 2     "data": [
 3         {
 4             "type": "commands",
 5             "id": "6a7ylqea1LsDqXb8V",
 6             "attributes": {
 7                 "id": "6a7ylqea1LsDqXb8V",
 8                 "voice_cmd": "on",
 9                 "machine_label": "on",
10                 "label": "On",
11                 "description": "Sends an on command",
12                 "public": 2,
13                 "status": 1,
14                 "created_at": 1482065387,
15                 "updated_at": 1518130546
16             },
17             "links": {
18                 "self": "https://api.yombo.net/api/v1/commands/6a7ylqea1LsDqXb8V"
19             }
20         },
21         {
22             "type": "commands",
23             "id": "pVZQKBgg5aI3BglM7",
24             "attributes": {
25                 "id": "pVZQKBgg5aI3BglM7",
26                 "voice_cmd": "off",
27                 "machine_label": "off",
28                 "label": "Off",
29                 "description": "Sends an off command",
30                 "public": 2,
31                 "status": 1,
32                 "created_at": 1482065387,
33                 "updated_at": 1482065387
34             },
35             "links": {
36                 "self": "https://api.yombo.net/api/v1/commands/pVZQKBgg5aI3BglM7"
37             }
38         },
39         {
40             "type": "commands",
41             "id": "pVZQKBg9yzTd0glM7",
42             "attributes": {
43                 "id": "pVZQKBg9yzTd0glM7",
44                 "voice_cmd": "close",
45                 "machine_label": "close",
46                 "label": "Close",
47                 "description": "Sends a close command",
48                 "public": 2,
49                 "status": 1,
50                 "created_at": 1482065387,
51                 "updated_at": 1482065387
52             },
53             "links": {
54                 "self": "https://api.yombo.net/api/v1/commands/pVZQKBg9yzTd0glM7"
55             }
56         }
57     ],
58     "meta": {
59         "count": 3,
60         "current_page": 1,
61         "from": 1,
62         "last_page": 12,
63         "path": "https://api.yombo.net/api/v1/commands",
64         "per_page": 3,
65         "to": 3,
66         "total": 34,
67         "includable": [
68             "users"
69         ]
70     },
71     "links": {
72         "first": "https://api.yombo.net/api/v1/commands?page%5Bsize%5D=3&page%5Bnumber%5D=1",
73         "last": "https://api.yombo.net/api/v1/commands?page%5Bsize%5D=3&page%5Bnumber%5D=12",
74         "prev": null,
75         "next": "https://api.yombo.net/api/v1/commands?page%5Bsize%5D=3&page%5Bnumber%5D=2",
76         "self": "https://api.yombo.net/api/v1/commands"
77     }
78 }

GET - Specific command

Retrieve a specific command id.

Request URL

  • GET https://api.yombo.net/api/v1/commands/{command_id}

Parameters

None

Example

  <div id="curl<random_number></random_number>" class="tab-pane fade in active" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
curl \
-H "x-api-key: abc123xyz789" \
-H "authorization: Bearer Waro7g0Mwl4YBJ..." \
https://api.yombo.net/api/v1/commands/pVZQKBg9yzTd0glM7
  <div id="python<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
import requests

url = 'https://api.yombo.net/api/v1/commands/pVZQKBg9yzTd0glM7
headers = {
    'x-api-key': 'abc123xyz789',
    'authorization': 'Waro7g0Mwl4YBJ...',
    }
response = requests.get(url, headers=headers)
  <div id="output<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
 1 {
 2     "data": {
 3         "type": "commands",
 4         "id": "pVZQKBg9yzTd0glM7",
 5         "attributes": {
 6             "id": "pVZQKBg9yzTd0glM7",
 7             "voice_cmd": "close",
 8             "machine_label": "close",
 9             "label": "Close",
10             "description": "Sends a close command",
11             "public": 2,
12             "status": 1,
13             "created_at": 1482065387,
14             "updated_at": 1482065387
15         },
16         "links": {
17             "self": "https://api.yombo.net/api/v1/commands/pVZQKBg9yzTd0glM7"
18         }
19     },
20     "links": {
21         "self": "https://api.yombo.net/api/v1/commands/pVZQKBg9yzTd0glM7"
22     },
23     "meta": {
24         "includable": [
25             "users"
26         ]
27     }
28 }

POST - Create new command

Creates a new command. Rules for public and status fields apply.

Request URL

  • POST https://api.yombo.net/api/v1/commands

Parameters

Name Type Description
Required
machine_name string Machine name for this comand. Once set, this cannot be changed. Can only contain: a-z and _ (underscore).
label string A short human friendly label for the command.
description string A detailed description of what the command does.
Optional
voice_cmd string Used by various systems to compile a possible list of voice commands for devices. This is what the person would say or type to activate the command. Usually the same as the label or machine_label.
status integer Default: 1 - Status for the command.
public integer Default: 0 - If the command should be public.

Example

  <div id="curl<random_number></random_number>" class="tab-pane fade in active" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
curl \
-H "x-api-key: abc123xyz789" \
-H "authorization: Bearer Waro7g0Mwl4YBJ..." \
-X POST -d '{"label": "Disabler", "machine_name": "disabler", "description": "Disables something. This is a test command for demonstration."}' \
https://api.yombo.net/api/v1/commands
  <div id="python<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
import requests

url = 'https://api.yombo.net/api/v1/commands'
headers = {
    'x-api-key': 'abc123xyz789',
    'authorization': 'Waro7g0Mwl4YBJ...',
    }

payload = {
    "machine_name": "disabler",
    "label": "Disabler",
    "description": "Disables something. This is a test command for demonstration.",
    }

response = requests.post(url, headers=headers, json=payload)
  <div id="output<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
 1 {
 2     "data": {
 3         "type": "commands",
 4         "id": "krb1qXmmkyH1X0KyP",
 5         "attributes": {
 6             "id": "krb1qXmmkyH1X0KyP",
 7             "voice_cmd": "voice test",
 8             "machine_label": "mitch_command1",
 9             "label": "Mitch command1",
10             "description": "A mitch command...",
11             "public": 1,
12             "status": 1,
13             "created_at": 1554858883,
14             "updated_at": 1554858883
15         },
16         "links": {
17             "self": "https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP"
18         }
19     },
20     "links": {
21         "self": "https://api.yombo.net/api/v1/commands"
22     },
23     "meta": {
24         "includable": [
25             "users"
26         ]
27     }
28 }

PUT / PATCH - Update a command

Update a command. When using PUT, all required parameters must be sent. When using PATCH, only send in desired changes.

Request URL

  • PATCH https://api.yombo.net/api/v1/commands/{command_id}
  • PUT https://api.yombo.net/api/v1/commands/{command_id}

Parameters

See post new command parameters.

Example

  <div id="curl<random_number></random_number>" class="tab-pane fade in active" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
curl \
-H "x-api-key: abc123xyz789" \
-H "authorization: Bearer Waro7g0Mwl4YBJ..." \
-X PUT -d '{"label": "Disabler2", "description":
"Disables something. Even faster This is a test command for demonstration."}' \
https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP
  <div id="python<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
import requests

url = 'https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP'
headers = {
    'x-api-key': 'abc123xyz789',
    'authorization': 'Waro7g0Mwl4YBJ...',
    }

payload = {
    "label": "Disabler2",
    "description": "Disables something. Even faster This is a test command for demonstration.",
    }

response = requests.put(url, headers=headers, json=payload)
  <div id="output<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
 1 {
 2     "data": {
 3         "type": "commands",
 4         "id": "krb1qXmmkyH1X0KyP",
 5         "attributes": {
 6             "id": "krb1qXmmkyH1X0KyP",
 7             "voice_cmd": "voice test",
 8             "machine_label": "mitch_command222",
 9             "label": "Mitch 1121266",
10             "description": "A mitch command...",
11             "public": 1,
12             "status": 1,
13             "created_at": 1554858883,
14             "updated_at": 1554858962
15         },
16         "links": {
17             "self": "https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP"
18         }
19     },
20     "links": {
21         "self": "https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP"
22     },
23     "meta": {
24         "includable": [
25             "users"
26         ]
27     }
28 }

DELETE - Delete a command

Delete a command. This doesn't actually delete the command right away, but simply marks it for deletion later. This is the same as setting the status to 2. To undelete the command, simply change the status back to 1.

Request URL

  • DELETE https://api.yombo.net/api/v1/commands/{command_id}

Parameters

None

Example

  <div id="curl<random_number></random_number>" class="tab-pane fade in active" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
curl \
-H "x-api-key: abc123xyz789" \
-H "authorization: Bearer Waro7g0Mwl4YBJ..." \
-X DELETE https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP
  <div id="python<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
import requests

url = 'https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP'
headers = {
    'x-api-key': 'abc123xyz789',
    'authorization': 'Waro7g0Mwl4YBJ...',
    }

response = requests.put(url, headers=headers)
  <div id="output<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
 1 {
 2     "data": {
 3         "type": "commands",
 4         "id": "krb1qXmmkyH1X0KyP",
 5         "attributes": {
 6             "id": "krb1qXmmkyH1X0KyP",
 7             "voice_cmd": "voice test",
 8             "machine_label": "mitch_command1",
 9             "label": "Mitch command1",
10             "description": "A mitch command...",
11             "public": 1,
12             "status": 2,
13             "created_at": 1554858883,
14             "updated_at": 1554858909
15         },
16         "links": {
17             "self": "https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP"
18         }
19     },
20     "links": {
21         "self": "https://api.yombo.net/api/v1/commands/krb1qXmmkyH1X0KyP"
22     },
23     "meta": {
24         "includable": [
25             "users"
26         ]
27     }
28 }

GET - Meta Information

Get the current meta information. Used for sorting, filtering, and relations.

Request URL

  • GET https://api.yombo.net/api/v1/commands/meta}

Parameters

None

Example

  <div id="curl<random_number></random_number>" class="tab-pane fade in active" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
curl \
-H "x-api-key: abc123xyz789" \
-H "authorization: Bearer Waro7g0Mwl4YBJ..." \
-X DELETE https://api.yombo.net/api/v1/commands/meta
  <div id="python<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
import requests

url = 'https://api.yombo.net/api/v1/commands/meta'
headers = {
    'x-api-key': 'abc123xyz789',
    'authorization': 'Waro7g0Mwl4YBJ...',
    }

response = requests.put(url, headers=headers)
  <div id="output<random_number></random_number>" class="tab-pane fade" style="border: 1px solid #ccc; border-radius: 5px; padding: 0.7em;">
 1 {
 2     "data": {
 3         "type": "commands_meta",
 4         "id": "commands_meta",
 5         "attributes": {
 6             "sortable": [
 7                 "voice_cmd",
 8                 "machine_label",
 9                 "label",
10                 "public",
11                 "status",
12                 "created_at",
13                 "updated_at"
14             ],
15             "includable": [
16                 "users"
17             ],
18             "filterable": [
19                 "user_id",
20                 "original_user_id",
21                 "voice_cmd",
22                 "machine_label",
23                 "label",
24                 "public",
25                 "status",
26                 "created_at",
27                 "updated_at"
28             ]
29         }
30     }
31 }
This page was last edited on 12 April 2019.