add data to a group

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.
Locked
User avatar
breckymorris
 
Posts: 16
Joined: Wed Feb 06, 2019 11:25 pm

add data to a group

Post by breckymorris »

Hi,
I'm trying to add new data to a group:
and I've been trying everything I can think of and it's not working out.

https://io.adafruit.com/api/v2/{usernam ... stest/data
Content-Type: application/json
X-AIO-Key: {my_key}

Thanks,
Brecky

Code: Select all

{
  "created_at": "2022-04-05T04:49:42.000Z",
  "feeds": [
    {
      "temperature": 24.953125
    },
    {
      "pressure": 1020
    },
    {
      "voltage": 5.171875
    },
    {
      "card": 27
    }
  ],
  "location": {
    "ele": 0,
    "lat": 36.97322250000001,
    "lon": -122.02027734375
  }
}

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: add data to a group

Post by jwcooper »

Could you provide more context? What errors are you getting?

Here is the section in the api docs on how to add data to feeds via groups:
https://io.adafruit.com/api/docs/#create-group-data

"group_feed_data" should be the root object.

Here is the example from the docs:

Code: Select all

group_feed_data: { feeds: [ { key: string, value: string }, ... ], created_at: string (optional), location: { lat: number, lon: number, ele: number } (optional)}

User avatar
breckymorris
 
Posts: 16
Joined: Wed Feb 06, 2019 11:25 pm

Re: add data to a group

Post by breckymorris »

Hi,

This is the curl command that I'm sending minus the key and username along with the error:

Code: Select all

curl 
-H "Content-Type: application/json" 
-H "X-AIO-Key: (IO key)"
-X POST https://io.adafruit.com/api/v2/(userrname)/groups/bluestest/data.json 
-d "{\"feeds\":[{\"temperature\":\"24\"}, {\"pressure\":\"1019\"}, {\"voltage\":\"5\"}, {\"card\":\"26\"}]}"

{"error":"request failed - failed to save data to group bluestest."}%
I have a group named bluestest and have created 4 feeds:

temperature
pressue
voltage
card

I'm trying to add data to all the feeds in the 'bluestest' group with this command.

Thanks!
Brecky

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: add data to a group

Post by jwcooper »

Looks like you're missing the group_feed_data:

Code: Select all

curl
-H "Content-Type: application/json"
-H "X-AIO-Key: (IO key)"
-X POST https://io.adafruit.com/api/v2/(userrname)/groups/bluestest/data.json
-d "{group_feed_data: {\"feeds\":[{\"temperature\":\"24\"}, {\"pressure\":\"1019\"}, {\"voltage\":\"5\"}, {\"card\":\"26\"}]}}"

User avatar
breckymorris
 
Posts: 16
Joined: Wed Feb 06, 2019 11:25 pm

Re: add data to a group

Post by breckymorris »

Thanks - feel like it's getting closer. There is still some problem, though. New error is: "error":"request failed - JSON request body must include `feeds` property. but, I do have 'feeds' in it as you know.

Thanks,
Brecky

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: add data to a group

Post by jwcooper »

I went back and dug through this further, and I believe the below example should work. Apologies for the wrong direction earlier. I'll update our documentation with a curl example today.

Code: Select all

curl
-H "Content-Type: application/json"
-H "X-AIO-Key: (IO key)"
-X POST https://io.adafruit.com/api/v2/(userrname)/groups/bluestest/data.json
-d "{\"feeds\":[{\"key\": \"temperature\", \"value\": \"24\"}, {\"key\": \"pressure\", \"value\": \"1019\"}, {\"key\": \"voltage\", \"value\": \"5\"}, {\"key\": \"card\", \"value\": \"26\"}]}}"

User avatar
breckymorris
 
Posts: 16
Joined: Wed Feb 06, 2019 11:25 pm

Re: add data to a group

Post by breckymorris »

Hi,

Thank you! This looks like it works with one small change, which I'll print in case anyone reads this in the future. I removed the trailing '}' from the code that you posted last.

Code: Select all

curl -H "Content-Type: application/json" -H "X-AIO-Key: (key)" -X POST https://io.adafruit.com/api/v2/(username)/groups/bluestest/data.json -d '{"feeds":[{"key": "temperature", "value": "24"}, {"key": "pressure", "value": "1019"}, {"key": "voltage", "value": "5"}, {"key": "card", "value": "26"}]}'
A posted curl example will really help.

Thanks,
Brecky

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”