TenanciTenanci

Help centerIntegrations

Bubble

How to put a Bubble app on each customer's domain — what works out of the box, how to tell which customer is visiting and how to build the "Connect domain" button with the API Connector.

Bubble is where Tenanci was born: a single app, published on yourapp.bubbleapps.io or your own domain, serving every customer on their own domain. This guide covers what works without any setup, how the app finds out which customer it's serving, and how to build the "Connect domain" button with the API Connector.

What works out of the box

  • Login on the customer's domain: Bubble checks the page URL in the X-Bubble-R header; the edge swaps the customer's domain for the app's domain in that header, so login, sign-up and workflows just work.
  • TailorKit: the visual editor recognizes Bubble elements (including Repeating Groups, with the option to apply a change to all similar items) and uses your app's breakpoints. See TailorKit.
  • Static files straight from the origin (on by default): Bubble's JS and CSS files that never change are downloaded directly by the browser, skipping the edge after the first time. Less traffic, faster pages.
  • Installable app: Bubble serves the base app's manifest and icons; with the installable app turned on, the edge swaps them for the customer's branding.
  • Search bots: with Pre-rendering for bots on (domain → SEO → Site), Google and social networks get fully rendered HTML instead of an empty page waiting for JavaScript.

Find out who the customer is

There are two ways. Pick the one that fits your Bubble database.

By domain ("This url"): in the browser, This url is the address the visitor opened, which is the customer's domain. Store the domain on your data type (for example a domain field on Barbershop) and search by it:

  1. On the page, create a custom state customer of your customer type.
  2. On the Page is loaded event, use Set state with Do a search for Barbershops (domain = This url:extract with Regex (?<=://)[^/:]+ :first item):first item.
  3. Use customer in the page's texts, images and conditions.

With window.TENANCI (Toolbox plugin): Tenanci hands you the id you registered for the domain.

  1. Under domain → Settings → Customer for this domain, fill in the Customer id in your app (the barbershop's unique id, for example) and turn on Available in the browser (window.TENANCI).
  2. Install the Toolbox plugin and drop an Expression element on the page, with the code below.
  3. Use the Expression's value to look up the customer.
Expression (Toolbox)
window.TENANCI && window.TENANCI.tenant ? window.TENANCI.tenant.id : ''

"Connect domain" button with the API Connector

The customer portal link is created by a call to the Tenanci API. In Bubble, it lives in the API Connector, with the key kept on Bubble's server.

  1. Under API keys, create a key with the domains:write scope (ideally restricted to the project). Name it something like "Bubble integration (production)".
  2. In Bubble, go to Plugins → API Connector → Add another API and name it "Tenanci".
  3. Under Authentication, choose Private key in header, with Key name Authorization and Key value Bearer + your key.
  4. Click Import another call from cURL and paste the call below (it's the same one shown on the Integration tab, with your project id already in it).
  5. On the imported call, set Use as: Action and leave <tenantId>, <name> and <returnUrl> as dynamic parameters (uncheck Private on them).
  6. Click Initialize call so Bubble learns the response (the url field).
cURL for the API Connector
curl -X POST "https://api.tenanci.com/v2/projects/prj_8f3k2m/portal/sessions" \
  -H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"tenantId":"<tenantId>","tenantData":{"name":"<name>"},"returnUrl":"<returnUrl>"}'

Now the button:

  1. On your app's settings page, add a "Connect my domain" button.
  2. In the button's workflow, add the Plugins → Tenanci - (call name) action, with tenantId = the logged-in user's customer unique id, name = their name and returnUrl = This url.
  3. Add Open an external website with Result of step 1's url.

Create the domain straight from Bubble

Prefer your own screen instead of the portal? Create the domain with POST /domains in a second API Connector call. The response includes the DNS record (dns.type, dns.name, dns.values) to show the customer.

cURL for the API Connector
curl -X POST "https://api.tenanci.com/v2/domains" \
  -H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"projectId":"prj_8f3k2m","hostname":"<hostname>","tenant":{"id":"<tenantId>","data":{"name":"<name>"},"expose":true}}'

The tenant field registers the domain's customer right away, so window.TENANCI works from the first visit. DNS details are in DNS.

Performance

Under domain → Settings → Performance:

  • keep Static files straight from the origin on (the default). Turn it off only if the customer must not see the app's original address in those file requests;
  • keep HTML cache set to Off. Bubble builds the page with the logged-in user's data, and the HTML cache is meant for sites where the page is the same for everyone.

Bubble plugin

There's no Tenanci plugin on the Bubble marketplace yet. Today's path is the API Connector (above) for "Connect domain" and TailorKit for each customer's branding without code.

Common problems

Symptom What to do
The call returns 400 portal_disabled Turn the portal on under project → Customer portal and save
The call returns 403 feature_not_in_plan The portal is on the Growth and Scale plans (see plans)
The Expression is empty Check Available in the browser on the domain and test on the customer's domain, not in preview
Searching by This url finds nobody Make sure the stored domain has no https:// and no extra www.