I'm trying to create a populated dashboard via the REST API. I have feeds setup and working and I can manually create a dashboard view the web interface.
Using the REST API, I'm able to create a dashboard with a POST to /api/v2/{username}/dashboards.
I'm also able to create a block under that dashboard with a POST to /api/v2/{username}/dashboards/{dashboard_key}/blocks.
However I can't figure out how to associate my feeds in the block_feeds section of the block. I've tried adding them into the block before it's created, but when the block comes back there are no feeds in it. I also tried guessing at an undocumented REST API path for appending block_feeds to a block, but couldn't figure that out.
Attached is a script that demonstrates what I'm doing along with an output log.
Creating Dashboards via REST API
Moderators: adafruit_support_bill, adafruit
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- cj8scrambler
- Posts: 7
- Joined: Wed Jun 29, 2016 4:47 pm
Creating Dashboards via REST API
- Attachments
-
- output.txt
- (1.83 KiB) Downloaded 11 times
-
- dasboard.py
- (1.64 KiB) Downloaded 17 times
- jwcooper
- Posts: 1004
- Joined: Tue May 01, 2012 9:08 pm
Re: Creating Dashboards via REST API
Here are the docs for this:
https://io.adafruit.com/api/docs/#create-a-block
Ideally, you pass in the feeds into block_feeds on creation of the block.
Try formatting it like so, block_feeds takes an array of objects with group_id and feed_id:
A good way to test this out is to use the developer console on the dashboard and watch the network requests when creating actual blocks. The IO web client uses the same API that is publicly available (for the most part).
https://io.adafruit.com/api/docs/#create-a-block
Ideally, you pass in the feeds into block_feeds on creation of the block.
Try formatting it like so, block_feeds takes an array of objects with group_id and feed_id:
Code: Select all
{"block":{"dashboard_id":{dashboard_id},"visual_type":"toggle_button","block_feeds":[{"group_id":{group_id},"feed_id":{feed_id}}],"properties":{"onText":"ON","onValue":null,"offText":"OFF","offValue":null},"name":"test","column":null,"row":null,"size_x":4,"size_y":2}}
- cj8scrambler
- Posts: 7
- Joined: Wed Jun 29, 2016 4:47 pm
Re: Creating Dashboards via REST API
Thanks. The hint to use the developer console helped. I'm now able to create a working dashboard.
There are definitely some peculiarities in the dashboard APIs. These were the biggest hurdles I came across:
There are definitely some peculiarities in the dashboard APIs. These were the biggest hurdles I came across:
- the the block_feeds section, feed_id and group_id are the id element even though key is used everywhere else in the API
- in the layouts section, it seems that only the lg layout is used
- in the layouts section, the i element (block id) MUST BE A STRING even though id is an int everywhere else
- jwcooper
- Posts: 1004
- Joined: Tue May 01, 2012 9:08 pm
Re: Creating Dashboards via REST API
Thanks for the follow-up and details on the peculiarities of the dashboard APIs.
Generally, I don't think many folks use it, and it's mostly used internally, so we haven't had much feedback on it. Your feedback is useful!
Generally, I don't think many folks use it, and it's mostly used internally, so we haven't had much feedback on it. Your feedback is useful!
- cj8scrambler
- Posts: 7
- Joined: Wed Jun 29, 2016 4:47 pm
Re: Creating Dashboards via REST API
The web interface for dashboard management works fine when you have a static set of feeds. But I wanted to be able to handle dynamically adding/removing feeds and updating the dashboards accordingly.
In order to get it all working in Python, I extended the Adafruit IO Python module to add support for dashboards: https://github.com/adafruit/Adafruit_IO_Python/pull/136 I hope the PR is accepted so that others can make use of this in the future with less struggles than I had.
In order to get it all working in Python, I extended the Adafruit IO Python module to add support for dashboards: https://github.com/adafruit/Adafruit_IO_Python/pull/136 I hope the PR is accepted so that others can make use of this in the future with less struggles than I had.
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.