https://supabase.com/ logo
#help
Title
# help
h

HoXsan

08/07/2021, 6:22 PM
Hi guys, is it possible to call third party API within supabase or postgres? Eg. I want to create user in Stripe, when a new user is created in Supabase. When calling the create API within Stripe, i want to store the stripe user ID in my Supabase DB. Is it possible to do it with supabase?
b

burggraf

08/07/2021, 8:07 PM
Yep! I do it all the time with the PostgreSQL extension HTTP. I like to use JavaScript to write my functions, so I have a library for this: https://github.com/burggraf/supascript
There are examples of using http with my library, you can check out the http docs in my repo.
Or you can use the http extension directly in your functions: https://github.com/pramsey/pgsql-http
h

HoXsan

08/07/2021, 8:22 PM
Interesting! Seems like it will fix the "problem" without needing to build an external API for this.
b

burggraf

08/08/2021, 2:03 AM
Definitely. We use Stripe internally at Supabase so it should work very well for you.
h

HoXsan

08/08/2021, 8:43 AM
But what is best practice? Using it directly on db layer or creating new api?
Im just a bit concerned about typings and testability
b

burggraf

08/08/2021, 12:27 PM
Best practice probably depends on your use case and what you're comfortable with. Supabase is pretty flexible so you could do it a few different ways. You could write your own server-based layer to talk to Stripe, or you could write PostgreSQL functions to do it. And you could write those PostgreSQL functions in SQL, PLPGSQL, JavaScript (PLV8), or other languages PostgreSQL supports. You could write it as functions that are called by the client through
rpc()
, or by functions that are called by PostgreSQL trigger functions (such as, when a new user is created, a Stripe account is created, then the new Stripe Customer ID is added to a Users table, etc.
j

jak

10/02/2021, 2:12 PM
Very interesting thread!I had considered using pipedream.com to create a Stripe customer from supabase but a postgres function seems like the way to go. @User I enjoyed your github repos for send email + SMS, I'll try and wrap my head around how to create a similar function but for creating a stripe customer.
If I work it out, i'll share the repo here... but if someone beats me to it 👏
b

burggraf

10/03/2021, 1:15 PM
Very interested to see this!
2 Views