#Idiots Guide to Using littleBits cloudBit API
##Introduction
- Connect a cloudBit to your network using the instructions at http://control.littlebitscloud.cc/
- Find out your AccessToken
- visit http://control.littlebitscloud.cc/
- on the left hand side select any of your cloudBits
- using the tab bar at the bottom select settings
- scroll down and copy your AccessToken
- Find a REST client to test with; I use either Chrome app REST client or http://apigee.com/console
##Setting Up Headers
- Include an 'Authorization' header 'Bearer XXXX' where XXXX is your AccessToken you need the word Bearer
- Include an 'Accept' header 'application/vnd.littlebits.v2+json'
- Include a 'Content-Type' header 'application/json'
##Current URL 'http://api-http.littlebitscloud.cc/v2/'
##GET All Connected Devices
- Change the request url to = 'http://api-http.littlebitscloud.cc/v2/devices/'
- Ensure you have:
- Authorization header
- Accept Content Type header
- Content Type header
- Click GET
\\\request
POST /v2/devices HTTP/1.1
Authorization: Bearer d64e5f77f9c60f00b4999ca2539ef61394e7b3beef00ce0856cb1aa9976871fa
Host: api-http.littlebitscloud.cc
Content-Length: 46
X-Target-URI: http://api-http.littlebitscloud.cc
Accept: application/vnd.littlebits.v2+json
Content-Type: application/json
Connection: Keep-Alive
\\RESPONSE
[
{
"id": "00e04c2241e8",
"user_id": "20702",
"label": "Oshawott",
"is_connected": true,
"ap": {
"ssid": "BTHub4-JWPJ",
"mac": "CC:33:BB:21:63:30",
"strength": "81"
},
"subscribers": [],
"subscriptions": []
}
]
##POST Data to Connected Device
- Connect a green output bit preferably something you can see numbers on, either a number bit or bargraph.
- Using 'GET all connected devices' request establish which cloudBit you need to talk to - save it's device_id somewhere
- Change the request url to 'http://api-http.littlebitscloud.cc/v2/devices/XXXX/output' where XXXX is the device_id
- In the request payload supply the following json:
{
"percent":50,
"duration_ms":5000
}
- percent needs to be a whole number between 0 and 100.
- duration_ms is the number of milliseconds to run, -1 runs forever (or until something interrupts it)
- Ensure you have:
- Authorization header
- Accept Content Type header
- Content Type header
- Click POST
///REQUEST
POST /v2/devices/00e04c2241e8/output HTTP/1.1
Authorization: Bearer d64e5f77f9c60f00b4999ca2539ef61394e7b3beef00ce0856cb1aa9976871fa
Host: api-http.littlebitscloud.cc
Content-Length: 46
X-Target-URI: http://api-http.littlebitscloud.cc
Accept: application/vnd.littlebits.v2+json
Content-Type: application/json
Connection: Keep-Alive
{
"percent": 50,
"duration_ms": 5000
}
///RESPONSE
OK
Thanks for the post ,exactly what I was looking for.
One small comment,
I only have one cloudbit, so to GET connected device I pass the request URL as 'https://api-http.littlebitscloud.cc/devices/DEVICE_ID'