Nov 06, 2022 05:37 AM
If a record is updated it would be awesome to sent the data to a webhook url. How would you do that?
Nov 06, 2022 06:12 AM
If you want it to happen automatically, you would need to setup an automation that runs a script. Check out the thread here:
If you need to send multiple pieces of data to your webhook, that thread shows you how to write the script for that.
However, as also mentioned in that thread, if you’re using an integration tool like Make’s webhooks, the simplest & easiest & best thing to do would be to just send the RecordID on its own to Make’s webhook, and then use the Airtable - Get A Record module to pull in all the rest of the field values from your record, including any linked record fields, attachment fields, etc. Then you would have full access to all of your field values.
This is how you would send just the Record ID on its own to a webhook in Make:
let config = input.config();
let url = `https://hook.us1.make.com/xxxxxxxxxxxxxxxxxxxxx?RecordID=${config.myRecord}`;
fetch(url);
Nov 06, 2022 03:40 PM
Hi @Tobias108 ,
You can see my video about how to use send data to webhook with script and process it further with Make here:
I usually find it faster to just send record ID to Make and pickup all other data from the record there, rather than attach all needed data to webhook URL with query (like …&datapoint=this&anotherdatapoint=that)
Nov 06, 2022 04:42 PM
In almost every case, this is a fine strategy. In certain edge cases, however, this will create some issues.
Imagine you have a record that changes, and at the instant it was changed, you need another system to rely specifically on that record’s values at that point in time. If you post the record ID to the endpoint, the next API call (or other request) to Airtable will be somewhat latent; it won’t be instant and may have just enough latency to allow other edits of the same record to sneak in. If that matters - and it seems to matter in more cases than you may think - you may have to POST the data payload with the outbound webhook event.
There are other issues to ponder as well. For every webhook call that triggers another inbound request, these are the things that occur:
Just sayin’ …
Nov 07, 2022 07:23 AM
“Simpler”, “easier”, “faster”, and “better” for whom? The end user or the developer?
Both techniques (sending all the appropriate data versus only the record id) are equally simple and easy for the end user. The end user doesn’t do anything different.
As @Bill.French pointed out, this technique of sending only the record ID and having Make query for the record data is slower for the end user and other users of the base. It also increases network traffic because Make fetches data for all fields in the record, not just the fields needed.
Thus I conclude that the technique of sending only the record ID is primarily “easier”, and “faster” for the developer, especially if the developer knows Make, but not JavaScript. Using the tool you know is always easier and faster than learning a tool that you do not yet know.
Here are some ways that having Make get the record data is simpler for the Make developer:
On there other hand, here are some potential benefits of sending the record data with the original webhook (especially if you know JavaScript).
Think about that last situation. Imagine that you have a complex base that uses multiple Make webhook scenarios. Something happens that trashes the base. You restore a snapshot. What would you rather do now:
Of course there are other reasons why you might not be able to continue with the snapshot (loss of record history, portals that are tied to a specific base, etc.). But in cases where it is possible, wouldn’t it be nice?
Nov 07, 2022 08:34 AM
Hey @Bill.French!
Yes, thanks for pointing it out. Especially in the case when there are multiple automation runs, these can take quite a while to process, so a record requested 1 min later might be something very different indeed.
“glue-factories” - love it :joy: yes, the glue factories should be applied more to hobbyist RC plane type of applications rather than full cargo flights.
Nov 07, 2022 08:37 AM
But should. :winking_face:
Huge advantage
Job security.
Opinion…
As y’all are aware, I’m deeply biased against glue-factory systems like Make. But, @kuovonne’s points are compelling enough to ask -
Should the term “expert” be applied to #no-code integrations?
There’s no question that one can get a lot done quickly at a fraction of the cost with Make. That ability seems to have a place at least at the innovation funnel for many organizations. But, should it be pervasively dependent deep inside the [production] architecture?
For the client’s benefit, experts are good at keeping them out of harm’s way. I’m not sure #no-code integrations do that. There’s a brightly-colored magenta elephant in this room, but I don’t think we can see him because the walls are magenta as well.
Nov 07, 2022 08:39 AM
Good metaphor. I used glue to build planes before there were tiny little engines for them. It was my first encounter with the term “sparingly apply …”.
Nov 07, 2022 10:01 AM
hey @Tobias108 ,
Following the discussion here is a code alternative that sends all the data with the request:
const {recordId} = input.config()
const imageTable = base.getTable("Image generation")
const url = "https://hook.com/"
//const fieldsToSend = ["Prompt","Number of images to generate","Status","Images"]
const fieldsToSend = imageTable.fields.map(({name})=> name);
const record = await imageTable.selectRecordAsync(recordId)
const recordData = Object.fromEntries(fieldsToSend.map(key => [key,record?.getCellValue(key)]))
await fetch(url,{
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({...recordData,recordId})
//alternatively you can follow Airtable API response convention
//body: JSON.string({id: recordId, fields:recordData})
})
@kuovonne pointed out ( :pray: ) it actually makes more sense to POST the data as the GET query parameters have limitation. Typing the fields names by hand especially without autocomplete is bit hard on me so decided to push all fields… obviously security/data size implications.
I hope it helps!
Nov 07, 2022 10:36 AM
Thanks for sharing. Now, for a really sharable script, I recommend rewriting it so that you do not need to hardcode the table name.
Yeah, typing out all field names is a bit annoying and also a maintenance issue. When sharing a generic script it is much easier to just send all the field data. However, for actual production use, I recommend only sending the necessary data, and in the shape desired by the webhook. For example, for attachments, you usually only need to send the url and possibly the filename. For single selects, you are probably better off sending the value as a string versus the cell read value of an object.
Nov 07, 2022 10:59 AM
Yes.
Some “no-code” integrations have the complexity of code and require expertise to build, understand, and maintain. I am in the minority, but I consider these complex systems to be code–they just don’t have to deal with as many spelling, grammar, and authentication issues as traditional code. And that is a good thing, because when you don’t have to worry about low-level things, you can focus on the actual logic at hand.
On the other hand, there are many levels of expertise, and no clearly accepted cross-platform accreditation system for who gets to call themselves experts. So just because someone calls herself an expert doesn’t mean very much.
Nov 08, 2022 05:17 AM
Is let config = input.config();
an accurate code? I have seen this in multiple threads and tried it but the scripting extension is indicating there is an error in it and won’t let me run the script.
Nov 08, 2022 05:20 AM
It is valid code for an automation script. It is not valid in Scripting Extension.
Nov 08, 2022 05:29 AM
Thanks @kuovonne. I was literally just reading Airtable dcumentation describing exactly this.
Much appreciated. :slightly_smiling_face: