One great feature of the Thingsquare platform is the ability to connect it to customer-specific software, such as a database system or your own app. This is done by using the Thingsquare API.
The Thingsquare API is a so-called REST API, which is an industry standard type of API with bindings available for every common programming language and platform.
Today we are looking at how to get started working with the API. This assumes a bit of experience with the command line and the
The Thingsquare platform architecture.
The API allows accessing devices and their data remotely and securely, using just standard HTTPS requests.
Today we are going to use the Demo Mode to play around with the API!
Step 0: Install
Before doing anything, you’ll need to have the
curl program installed. The
curl utility lets you perform REST API calls directly from the command line.
If you do not have
curl installed, download and install it:
Step 1: Turn on Demo Mode
Open the Thingsquare Device Viewer app, either on your iOS/Android phone or in your browser, turn on Demo Mode, and enable
If you do not yet have a user account, create one.
Demo Mode button …
… flip the switch …
… and enable remote access with the
Remote access checkbox
Step 2: Make a note of the device ID
After making the device remotely accessible, the device has acquired a unique device ID. This ID will be used to access the device via the API.
The device ID can be found on the
Details tab, all the way down. You may need to tilt your device to see the full device ID.
Go to the
Details tab and scroll all the way down
Tilt the device to see the full device ID
Make a note of your device ID – it will be used below.
Step 3: Create an API session
Next step is to create an API token for API access to your devices. Go to the
Account tab and tap the
API access checkbox.
Go to the
Account tab and create an API access token
Make a note of the API access token – this will be needed now.
Now we create an API session with the API access token above. This is done using the
curl command below:
curl -c sessioncookie.txt -X POST --data token=TOKEN https://0ac48bf3-9fab-4bad-8455-e394808eda6b.developer.thingsquare.com/0/session/
You should replace the word
TOKEN with your own access token.
This should result in a single line of output:
And the API session is setup!
Step 4: Set the color of the demo device
Now we have created an API session that we can use to send and receive data to and from our devices.
We do this with another
curl command – note the
-b switch (it was
curl -b sessioncookie.txt -X POST --data value=#00ff00 https://0ac48bf3-9fab-4bad-8455-e394808eda6b.developer.thingsquare.com/0/devices/ID/d/leds
Where you should replace the word
ID with the device ID that you saw under the
Details tab in the app.
This should now make the virtual lamp shine up with a horrible green light. Change the
#00ff00 in the command above to set a nicer color. The colors are standard HTML hex colors.
A horrible green colored light.
To learn more about the Thingsquare platform API, check out our developer documentation! Specifically: