Help

Re: Button to create data | API

1398 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Dr_Dark
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello.

I’m having some issues with a website i’m making.
Would it be possible for anyone to give me a quick guide on how i’d make an HTML button that’ll submit some data from boxes?

I already have this code below, but it seems it’ll only recognize require in my server.js, but i obviously can’t refer to code in there.
Everywhere else i just get require is not defined.

var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('YOUR_BASE_ID');

base('MissedAttacks').create({
"Username": "$Jujubeez$",
"AttacksMissed": "2",
"Date": "2008-01-18",
"Total Stars": "50 | 54",
"Is Valid": true,
"Which Clan": "Main"
}, function(err, record) {
if (err) {
console.error(err);
return;
  }
  console.log(record.getId());
});
12 Replies 12

But this seems like an awfully complicated way to do this?

This code below is enough to create data and send it to my server.

var Airtable = require(‘airtable’);
var base = new Airtable({apiKey: process.env.API_KEY}).base(process.env.BASE.ID);

base(‘MissedAttacks’).create({
“Username”: “Jujubeez”,
“AttacksMissed”: “2”,
“Date”: “2008-01-18”,
“Total Stars”: “50 | 54”,
“Is Valid”: true,
“Which Clan”: “Main”
}, function(err, record) {
if (err) {
console.error(err);
return;
}
console.log(record.getId());
});

Isn’t there an easier way to just extract the values into that?

Hmm i think i found something. What if i turn the above into a function, and leave it on server-side, and then do this:
https_://stackoverflow._com/questions/43597543/how-to-call-server-side-function-from-html-button-not-in-a-form-using-expressj

Please remove the 2x _'s

Not really - you have a web app and totally separate, you have a server that is communicating with Airtable. If you want to create a client-server application there are some essential elements that need to work, and all in a way that doesn’t compromise security.

There is a pure client-side SDK for Airtable - I referenced it way above. Using it, you could go direct from the web app to Airtable (and back). This would negate the need to develop your own NodeJS server, but it would also require some additional considerations in the design of your app. It also creates cross-domain security issues that you’d need to program for.

I thought that’s what you were doing - the require() method suggests it is server-side already. Is it working as shown?