Adding a record to a Supabase table from Custom JavaScript code

Hello. I would like to use Custom JavaScript in WeWeb to operate on my Supabase DB, i.e. to insert a record to a table. I tried the following simple example: JavaScript API Reference | Supabase Docs . The JavaScript code for the insert is:
const { error } = await supabase
.from(‘countries’)
.insert({ id: 1, name: ‘Denmark’ })
I have a table named countries (in the DB) and a corresponding collection named countries (in WeWeb) as well. The code does not work, though (says: invalid or unexpected token). I suppose that JavaScript still needs some more info to work in this context. What is needed to make it work? Will this approach work at all? Are there any other approaches? I did not try to use SQL, but this approach is ugly for me (possible SQL injection attack).
My concern is: Using a WeWeb action involving the Supabase plugin for the same goal may be not sufficient for me, since I am planning to write JavaScript logic around the insert. Any help is appreciated. Best, Greg

instead of await supabase use
await wwLib.wwPlugins.supabase.instance

also try using the built in weweb inserts as much as possible

I’d highly suggest not using Custom JavaScript for Supabase unless you hit a limitation of WeWeb which is hard to hit, and your usecase doesn’t seem like the case. Instead use the workflows and their actions, as they should cover all you need to do.

In order to do CRUD with you need to use
const supabase = wwLib.wwPlugins.supabase.instance before you do anything using the supabase instance.

Thank you for your prompt replies. Broberto, I’ve added your line at top of my JavaScript code, now I’ve got this message:
{
“message”: “No API key found in request”,
“hint”: “No apikey request header or url param was found.”
}
Please help further.
I will consider your hints to do as much as possible in WeWeb (not in JavaScript), but first I try JavaScript - the case is really simple and a traditional programming language seems to me a more natural solution to write some logic I need here. Best, Greg

The error you get means that you might have not set up the Supabase plugin correctly. Meaning that the Api Key is not filled.

Also, please use the according actions. This is considered a bad practice, especially if it’s doable with no-code.