Pardon the mess

You are viewing docs related to an older version of Sequin. We’re in the process of updating our provider-specific guides and will be done in a few weeks (May 2024). Please click here to view the latest version of the docs.

If you’re interested in Stripe and want to learn more about what’s changing, send us a note.

In just a couple of minutes, you’ll have a Postgres database with all your Stripe data, syncing in real-time.

Connect your Stripe API

First, add your Stripe secret key to Sequin:

Step 1: Create a new Sequin account at https://app.sequin.io/signup.

Step 2: Select Stripe as the platform you want to sync.

Select Stripe

Step 3: Provide us with your Stripe secret key (it should begin with the characters sk_live_). On our console, click the How do I get this? link if you need a little help generating your API key or follow this link to your Stripe dashboard.

Stripe API Page

As a best practice, we recommend you create a new Restricted secret key for Sequin. Sequin needs read permissions for everything and just write access for webhooks.

Step 4: Select the tables you want to sync. You can choose which fields will sync to your database and edit the column name for each field by clicking the gear icon.

Step 5: Connect to the destination database you want to sync your Stripe data to. We suggest you sync to a database you host by choosing the Connect option and following the steps to connect to your database. Or, if you want to get up and running quickly, click the Launch option to spin up a demo database we host for you (on Amazon RDS).

Step 6: Click Create.

Create your Sequin database

After you click Create, Sequin will begin backfilling all your data. We’ll show you the progress we’re making in the console. Within a minute or two, you can begin exploring your schema and querying your data in SQL. We’ll send you an email when your backfill is complete.

Sync complete

Query your Stripe data using SQL

Connect to your database via Sequin’s Postgres Proxy, which lets you write to your synced tables as well as read them. We’ll use psql as an example in this setup guide, but you can use any SQL client that works with Postgres.

Step 1: Go to Connection Instructions on the Sequin console. Copy the psql command to connect to your database via the Proxy.

Step 2: Open your terminal, and paste the psql command. Press Enter. This will open a connection to your database so you can write your first query:

psql -d {your_connection_string_here}
psql (14.2, server 12.11)
Type "help" for help.

stripe=>

Step 3: To get a sense of your schema, list all the tables you’re syncing to your database by typing the command \dt:

stripe=> \dt

               List of relations
                  List of relations
 Schema |           Name            | Type  | Owner
--------+---------------------------+-------+--------
 public | _sync_cdc                 | table | sequin
 public | _sync_event               | table | sequin
 public | _sync_event_cursor        | table | sequin
 public | charge                    | table | sequin
 public | customer                  | table | sequin
 public | order                     | table | sequin
 public | price                     | table | sequin
 public | refund                    | table | sequin
 public | upcoming_customer_invoice | table | sequin
(9 rows)

You’ll see all the Stripe objects you selected when setting up your sync are now tables in your database. You’ll also see some _sync tables which Sequin uses to manage your sync.

Step 4: Write your first query. You can start with a simple select to get your bearings:

stripe=> select count(*) from customer;

 count
-------
    15
(1 row)

Now, pull the contact id, name, and address for a specific customer to use in the next step:

stripe=> select id, name, address_city from customer where email = 'carter@sequin.io';
         id         |      name       | address_city
--------------------+-----------------+--------------
 cus_OnQaeodsV7avVL | Carter Pedersen | Santa Monica
(1 row)

Great, you can now use this id in the last step of this setup guide.

Write back to Stripe

To create, update, or delete objects in Stripe, you can insert, update, or delete rows in your Postgres database.

When you’re connected to your database through the Sequin Proxy, the Proxy listens for changes. When you make a mutation, the Proxy applies the mutation to Stripe’s API first. If the mutation succeeds, your database is updated as well. If it fails, your database mutation will be rolled back, and you’ll receive a Postgres error.

In this example, you’ll update the customer in the prior step by giving them a new shipping address:

update customers
set address_city = 'San Francisco'
where id = '{{customer_id}}'

This call will update the first and last name of that contact. If the Postgres write returned without an error, that means the API write succeeded as well!

You can see over on Stripe that the record has updated.

Step 3: Now, confirm the change in your database. Go back to psql and check the contact you just updated:

stripe=> select address_city from customer where id='{{customer_id}}';

 address_city
--------------
 San Francisco
(1 row)

Great, Stripe and your database were updated simultaneously.

Next steps

Your Stripe tables are now available as fully readable and writeable tables in your database. You can query for all your data using SQL, and mutate data thanks to Sequin’s Postgres Proxy. To build on this foundation, here are some next steps:

  • Setup your ORM to work with your synced tables.
  • Edit the Stripe objects and properties you’re syncing at any time.
  • Create views on your Stripe data to tailor your schema to your needs.
  • Invite your team to your Sequin account and start building!

If you need assistance setting up your sync, just send us a note. We’re around and eager to help.

Was this page helpful?