0

Create Feed data by simple http request
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Create Feed data by simple http request

by Petros22 on Thu Jun 06, 2019 9:15 am

Hello

I'm new here.

Please tell me how can i store data (f.e. integer value 1234) to my feed by internet browser
(no curl or programming)

Code: Select all | TOGGLE FULL SIZE
https://io.adafruit.com/api/v2/my_username/feeds/my_feed/data?value=1234&x-aio-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx


is not working for me

my_username and my_feed are correct

This is working fine and i see all feed values:
Code: Select all | TOGGLE FULL SIZE
https://io.adafruit.com/api/v2/my_username/feeds/my_feed/data?x-aio-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx


thank you!

Petros22
 
Posts: 2
Joined: Thu Jun 06, 2019 8:59 am

Re: Create Feed data by simple http request

by abachman on Thu Jun 06, 2019 12:44 pm

Hi petros22,


Unfortunately, you won't be able to create new data by typing a URL into your browser's location bar. This is because the location bar only makes GET requests, but the HTTP data creation API requires POST requests.

You can use a snippet of javascript to make a POST request, though. Here's an example (with my API Key blanked out:

Code: Select all | TOGGLE FULL SIZE
fetch("https://io.adafruit.com/api/v2/abachman/feeds/color-set/data", { method: "POST", body: JSON.stringify({ datum: { value: "#33aabb" } }), headers: { "X-AIO-Key": "...", "Content-Type": "application/json" } }).then(function (response) {
  return response.json()
}).then(function (json) {
  console.log("GOT", json)
})


You'll need to change the username, feed key, AIO Key, and value to customize it for your own usage. That snippet works for me in Chrome and Firefox. Since that feed is public, you can see the value I published last with this snippet:
Code: Select all | TOGGLE FULL SIZE
fetch("https://io.adafruit.com/api/v2/abachman/feeds/color-set/data?limit=1").then(function (r) { return r.json() }).then(function (json) { console.log("LAST DATA WAS", json[0]) })

You can find more info on the fetch command here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

There really isn't any way to publish data to IO without either writing code or logging into io.adafruit.com and visiting the feed page or a dashboard that includes the feed. If you need a URL that you can publish to, use a feed webhook instead of including your secret key in the URL.

If you want to publish to the feed from a plain HTML form, you can find an example of that on our announcement blog post here: https://io.adafruit.com/blog/notebook/2 ... -webhooks/.

Hopefully there's some information there to help you. What kind of project are you working on?


- adam b.

abachman
 
Posts: 292
Joined: Mon Feb 01, 2010 12:48 pm

Re: Create Feed data by simple http request

by Petros22 on Fri Jun 07, 2019 2:55 am

Thank you for your help abachman!

My project is ebike/car tracking device. I'm a embedded C developer, and i have already a working mqtt publischer on arduino + gps.

My goal is now to find a easiest way to make an android smartphone application for reading/writing data to feed.
My new idea ist to use MIT App Inventor... But what would be the best way to connect Adafrit.io to MIT App Inventor?
In MIT App inventor i would have a full control over my data on smartphone....

Petros22
 
Posts: 2
Joined: Thu Jun 06, 2019 8:59 am

Re: Create Feed data by simple http request

by brubell on Fri Jun 07, 2019 10:21 am

Petros22 wrote:Thank you for your help abachman!

My project is ebike/car tracking device. I'm a embedded C developer, and i have already a working mqtt publischer on arduino + gps.

My goal is now to find a easiest way to make an android smartphone application for reading/writing data to feed.
My new idea ist to use MIT App Inventor... But what would be the best way to connect Adafrit.io to MIT App Inventor?
In MIT App inventor i would have a full control over my data on smartphone....


There's a guide on the adafruit learning system about connecting App Inventor to Particle, the process might be similar for Adafruit IO.

Also, this may be useful - https://medium.com/kidstronics/adafruit ... dc7737cc7b

brubell
 
Posts: 402
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.