2

Is it possible to use Supabase with Google Apps Script (GAS)?

I'm new to Supabase and I've never tried to import external library to GAS before. I'm planning to use Supabase as a database for my project in GAS. The project is built to run a bot in a chatting platform rather than a user interface. Based on the documentation from Supabase, it looks like it works by executing function from the Supabase library.

I have tried to use the Supabase library by copy-pasting the whole library from here or using eval(), but all of them return the error: ReferenceError: self is not defined.

Here is the function I run that uses eval():

function myFunction(){
  var x = eval(UrlFetchApp.fetch("https://unpkg.com/@supabase/supabase-js").getContentText())
  var supabase = createClient(supabaseUrl,supabaseKey)
}

createClient() is supposed to be a function from the Supabase library.

  • Google Apps Script doesn't support the import and export statements apparently required by the linked library. Please add more details about what supabase features are looking to use on Google Apps Script an a brief description of how you will use them. Better if you include a [mcve]. – Rubén May 06 '22 at 13:32
  • Possible related https://stackoverflow.com/q/49204546/1595451 – Rubén May 06 '22 at 13:36
  • @Rubén thank you, I've updated some information on the post based on what I've tried – Ersih Frans May 06 '22 at 14:09
  • IMHO there isn't enough details yet. – Rubén May 06 '22 at 14:19
  • Have you tried creating a web app and use the JS from the – Kessy May 06 '22 at 15:10
  • @Kessy I've never tried using .html before because I don't build a user interface. My project is built to run a bot (I'll update this info on the post). Care to give me some guidance? – Ersih Frans May 06 '22 at 16:15
  • The html is to be able to call the library. Also note that to call the library is not correct on your side, it should be `libraryName.method`. You can also create another .gs file with the library functions and import it to your main project as a library. – Kessy May 09 '22 at 15:43

1 Answers1

2

One possible route that I can think of to make this work is to use Postgrest, which is the underlining API server that Supabase users.

Since every Supabase instance can be accessed using rest API provided by Postgrest, you should be able to perform insert, update, delete and read operations to your Supabase database from your GAS project.

You can probably run something like this to access Supabase.

$anonKey = "YOUR_SUPABASE_ANON_KEY_HERE"
$url = "YOUR_SUPABASE_URL_HERE"
$var options = {
     "async": true,
     "crossDomain": true,
     "method" : "GET",
     "headers" : {
       "Authorization" : "Bearer " + $anonKey,
       "apikey": $anonKey
     }
   };
var response = UrlFetchApp.fetch($url + "YOUR_QUERY_PARAMETER_FOR_POSTGREST", options);
dshukertjr
  • 15,244
  • 11
  • 57
  • 94