GraphQL examples and snippets
These are examples of queries which can be used regardless of the method of connecting to the GraphQL API.
Grabbing a sessionId
To quickly get a sessionId using you can use curl
:
Bash | |
---|---|
1 |
|
or the browser browsers bultin Fetch API. This can be directly pasted into the console of your web browser.
JavaScript | |
---|---|
1 2 3 4 5 6 |
|
Using the browser Fetch API
One of the simples methods of talking to the GraphQL API is, again, using your browsers console. If you have another favourite way of sending HTTP requests, feel free to use that instead.
JavaScript | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
To use this snippet replace the sessionId with the one you just got, and then paste it into the browser console. You might have to change the host to something that makes sense in your situation as well. To actually send a request we can write something like below:
JavaScript | |
---|---|
1 2 3 4 5 6 7 |
|
More queries
Get a list of locations
GraphQL | |
---|---|
1 2 3 4 5 6 7 8 |
|
Get a list of the first 10 dids found on a location
This example also uses variables in the query. If that seems scary you might find some comfort here: https://graphql.org/learn/
GraphQL | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 |
|
Get 10 conference rooms and their temperatures
Text Only | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Get a list of discovered devices and log a few of them
GraphQL | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
Provision a device
Note
This input performs a change to your system when executed.
This is a mutation, so make sure you are sending your requests somewhere non critical.
GraphQL | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|