Integrate: Share with Houseguest button
A Share with Houseguest™ button lets someone looking at an internal app share that app’s hostname with a
named person in one or two clicks, without opening the console first. It suits apps that create hostnames as
they go, such as one staging environment per branch at <branch>.apps.example.com.
There are two ways to wire it:
| Deep link | API | |
|---|---|---|
| What the app adds | A plain link | One call from the app’s server |
| Backend or token | None | A workspace API token, kept on the server |
| Who confirms | The person, signed in to the console | Your server, acting as the token’s member |
| Good for | Any page, static sites, dashboards | Apps that already have a server and want the link back in their own UI |
Both follow the same rules as the console: the hostname must be one an agent of the workspace forwards or allows, a name that is not turned on yet is turned on only for someone who may turn names on, and an open preview that already holds the hostname is reused rather than duplicated.
Before you start: the agent and DNS
Section titled “Before you start: the agent and DNS”Each hostname has to reach an agent, and the public name has to point at Houseguest.
-
A wildcard entry on the agent. Give the agent that can reach the apps a
*.entry inHG_ALLOW, for exampleHG_ALLOW=*.apps.example.com=dns(each name to the address its internal DNS gives). A wildcard allows any one name directly underapps.example.com, and the agent forwards a name only once it is turned on: by the button, or on the agent’s page. Names deeper than one label, such asa.b.apps.example.com, are never covered. See Allow-lists. -
A verified domain. The hostnames must be under a domain the workspace verified, such as
example.com(Domains & addresses). See Domains and addresses. -
DNS to your CNAME target. Point the names at your workspace’s target,
<short name>.edge.houseguest.dev, shown on Domains & addresses. One wildcard record covers every name:*.apps.example.com. CNAME acme.edge.houseguest.dev.The certificate for each name is fetched once its DNS points at Houseguest; the first share of a new name may say it is still being issued for a minute.
Turning a name on needs the Turn hostnames on and off permission. People without it can still share names that are already on.
The deep link (no backend)
Section titled “The deep link (no backend)”Link to the console’s /share page with the hostname, and optionally where to come back to:
https://console.houseguest.dev/share?host=<hostname>&return=<url>| Parameter | Meaning |
|---|---|
host |
The hostname to share. Several, comma-separated, share one preview; viewers land on the first. They must share a parent domain |
return |
Optional. Where Back to goes after sharing. Kept only when it is an https:// address on one of the hostnames being shared; anything else is dropped |
viewer_note |
Optional. The note for viewers of a new preview, plain text, shown filled in on the page (without it, the hostname’s default note). The note comes from the link, so the member reviews it on the page before Share. Never sign-in details: a link is no place for them |
The person clicks it, signs in if they are not signed in already (the link survives the sign-in), and sees what will be shared: the hostname, the agent that forwards it, whether it will be turned on, and the open preview that already holds it, if any. They can name people to invite, choose how long it stays open, and confirm with Share. The result page gives the link viewers use, whether DNS and the certificate are ready, and a way back to the app. More options opens the full New preview form with the hostname ticked.
The link names no workspace. Each domain is verified by one workspace, so the hostname already says which one it belongs to. People in several workspaces land in the right one: when the console is open in another of their workspaces, the page names the workspace that verified the hostname’s domain and offers Switch to Acme Staging. After the switch the page says so (Switched to Acme Staging.) and shows what will be shared. Opening the link never switches workspaces by itself. If that workspace asks for a second sign-in step or single sign-on, the person completes it first and then comes back to the page. Share acts only in the workspace the page shows.
Build the link from the page’s own hostname. Plain HTML, with the button styles below:
<link rel="stylesheet" href="https://houseguest.dev/docs/integrate/share-button.css"><a class="hg-share" id="hg-share" href="https://console.houseguest.dev/share"> <svg viewBox="0 0 32 32" aria-hidden="true"><path fill-rule="evenodd" d="M7 3h18v22.5H7zM9.8 5.8v19.7h8.4V8.4z"/><rect x="3.5" y="27.5" width="25" height="2.8" rx="1.4"/></svg> <span>Share with Houseguest<sup>™</sup></span></a><script> // This page's hostname, and back to this page afterwards. const a = document.getElementById('hg-share'); const u = new URL(a.href); u.searchParams.set('host', location.hostname); u.searchParams.set('return', location.href); a.href = u;</script>Or write the hostname into the link when the page is rendered, with no script at all:
<a class="hg-share" href="https://console.houseguest.dev/share?host=staging.apps.example.com&return=https%3A%2F%2Fstaging.apps.example.com%2F">…</a>If the hostname cannot be shared, the page says why and offers nothing to confirm: no agent of the workspace forwards or allows it, its domain is not verified, it is in another open preview, or turning it on needs a permission the person does not hold. It never shows anything of another workspace: someone who is not a member of the workspace that verified the domain sees the hostname as not forwarded here, with no switch and no workspace named.
The API (from your server)
Section titled “The API (from your server)”POST /api/v1/shares does the same in one call: it turns the name on if needed, reuses the open preview that
holds it or opens one, invites the people you name, and answers with the link and whether it is ready yet.
Repeating the call with the same body changes nothing, so a second click on the button is safe.
The token
Section titled “The token”In Settings → API tokens, create a token with only these scopes:
| Scope | Why |
|---|---|
Create previews (previews.create) |
Required by POST /shares |
Turn hostnames on and off (agents.names) |
To turn on a name under a wildcard entry. Leave it out if every name is already on |
Invite viewers (viewers.invite) |
Only if the call names viewers |
Manage own previews (previews.manage_own) |
Only to add a hostname to an open preview the token’s member opened, or to use the hostname endpoints below on such previews |
Manage any preview (previews.manage) |
Only to add hostnames to open previews other members opened. previews.manage_own never reaches those, even for an admin’s token |
The token’s member must hold each permission, and the token can never do more than that member can at the moment of the call.
For a one-off from a terminal, with the hostname typed in:
curl -sS https://console.houseguest.dev/api/v1/shares \ -H "Authorization: Bearer $HOUSEGUEST_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "hostname": "staging.apps.example.com", "lifetime_seconds": 259200 }'The answer is 201 when a new preview opened, 200 when an open preview already held the hostname:
{ "object": "share", "result": "created", "share_url": "https://staging.apps.example.com/", "ready": false, "preview": { "object": "preview", "id": "k3x7q2m5w4p5r6t2", "name": "staging", "status": "open", "expires_at": "2026-11-05T09:00:00Z" }, "hostnames": [ { "hostname": "staging.apps.example.com", "agent_id": "ag_3", "turned_on": true, "dns": "edge", "dns_ready": true, "dns_record": "managed", "certificate": "pending", "certificate_ready": false } ], "invites": []}| Field | Meaning |
|---|---|
result |
created (a new preview) or reused (an open preview held the hostname; missing hostnames and new people were added to it, nothing else changed) |
share_url |
Where viewers start |
ready |
Every hostname’s DNS points at Houseguest and no certificate is still being issued |
hostnames[].turned_on |
This call turned the name on |
hostnames[].dns_record |
Who makes the name’s DNS record, when the workspace uses DNS automation: managed (Houseguest created it and keeps it), pending (not created yet), conflict (a record Houseguest did not make is in the way; see the domain’s page), by_hand (this name’s record is made by hand), or none (no DNS automation for the domain) |
hostnames[].certificate |
ready, pending (being issued), waiting_for_dns, or unknown (issued on the first visit) |
invites[].delivery |
emailed, queued (a scheduled preview), link (with "notify": false: invite_url is shown once), already_invited (the person was already invited, or was revoked; nobody is re-admitted) |
Other request fields: hostnames (more names for the same preview), viewers, note, viewer_note (the
note for viewers of a new preview, since 1.7.0; a preview reused keeps its own), name (default: the
first label of the hostname, staging), notify (default true). lifetime_seconds applies only to a new
preview; the workspace’s default length is used without it. An Idempotency-Key header makes retries return
the first answer, as on every POST.
A name the call turns on gets its DNS record from DNS automation when that covers its domain, by the domain’s default; the API has no per-call choice. Set a name to be made by hand on the domain’s page.
JavaScript (Node 18 or later)
Section titled “JavaScript (Node 18 or later)”A small helper with no dependencies is published at
/docs/integrate/houseguest-share.mjs. Copy it into your app, or call
the API with fetch directly. An Express route, behind the app’s own staff sign-in and CSRF check, with the
hostname from configuration:
// server.js: the button posts here. The token and the hostname stay on the server.import { share, HouseguestError } from './houseguest-share.mjs';
const HOSTNAME = process.env.APP_PUBLIC_HOSTNAME; // this app's own name, e.g. staging.apps.example.com
app.post('/share-with-houseguest', requireStaffSession, // your app's sign-in: staff only csrfProtection, // your framework's CSRF check async (req, res) => { // Viewers only from staff allowed to invite; otherwise none (invite from the console). const viewers = req.user.canInvite && Array.isArray(req.body.viewers) ? req.body.viewers.slice(0, 20) : undefined; try { const out = await share({ token: process.env.HOUSEGUEST_TOKEN, hostname: HOSTNAME, viewers }); res.json({ url: out.share_url, ready: out.ready, preview: out.preview.console_url }); } catch (e) { if (e instanceof HouseguestError) return res.status(e.status).json({ code: e.code, message: e.message }); throw e; } });requireStaffSession, req.user.canInvite and csrfProtection stand for your app’s own sign-in, roles and
CSRF middleware. The helper’s shareLink({ host, returnTo }) builds the deep link instead, and is safe in
pages; share() refuses to run in a browser or a Web Worker.
Python
Section titled “Python”A Flask view, with the same rules: staff only, CSRF checked (Flask-WTF’s CSRFProtect), the hostname from
configuration, viewers only from staff allowed to invite:
import json, os, urllib.request, urllib.errorfrom flask import Flask, abort, jsonify, requestfrom flask_login import current_user, login_required # your app's sign-infrom flask_wtf.csrf import CSRFProtect
app = Flask(__name__)CSRFProtect(app) # every POST needs the CSRF tokenHOSTNAME = os.environ["APP_PUBLIC_HOSTNAME"] # this app's own name; never from the request
def share_with_houseguest(viewers=None): body = {"hostname": HOSTNAME} if viewers: body["viewers"] = viewers req = urllib.request.Request( "https://console.houseguest.dev/api/v1/shares", data=json.dumps(body).encode(), headers={ "Authorization": "Bearer " + os.environ["HOUSEGUEST_TOKEN"], "Content-Type": "application/json", }, method="POST", ) try: with urllib.request.urlopen(req, timeout=30) as r: return json.load(r) except urllib.error.HTTPError as e: err = json.load(e)["error"] raise RuntimeError(f"{err['code']}: {err['message']}") from None
@app.post("/share-with-houseguest")@login_requireddef share_route(): if not current_user.is_staff: abort(403) viewers = None if current_user.can_invite: viewers = [v for v in (request.get_json(silent=True) or {}).get("viewers", []) if isinstance(v, str)][:20] out = share_with_houseguest(viewers) return jsonify(url=out["share_url"], ready=out["ready"])Smaller steps
Section titled “Smaller steps”The same rules are available one step at a time, for tools that manage names and previews themselves:
| Call | Scope | Does |
|---|---|---|
POST /agents/{agent_id}/hostnames {"hostname": …} |
agents.names |
Turns one name on under the agent’s *. entry: 201, or 200 when it was on |
DELETE /agents/{agent_id}/hostnames/{hostname} |
agents.names |
Turns it off. Refused while the name is in an open preview |
POST /previews/{preview_id}/hostnames {"hostname": …} |
previews.manage_own (previews the token’s member opened) or previews.manage (any) |
Adds a hostname to an open preview; a name not on yet also needs agents.names |
DELETE /previews/{preview_id}/hostnames/{hostname} |
previews.manage_own or previews.manage, as above |
Removes it; viewers lose it at once. The landing hostname stays |
Every field is in the API reference.
In the console
Section titled “In the console”The console’s own forms work the same way. In New preview, Another hostname takes one name under an
agent’s *. entry and turns it on with the preview; the preview page’s Add hostname does the same. Both
need Turn hostnames on and off for a name that is not on yet, and say so when it is missing. Only the name
you type is turned on, never everything under the wildcard.
Where the workspace uses DNS automation for the name’s domain, these forms and
the deep link’s confirm step show Create the DNS record at
Errors
Section titled “Errors”| Code | Status | Meaning | What to do |
|---|---|---|---|
hostname_not_covered |
422 | No agent of the workspace forwards the hostname, and none allows it one label under a *. entry |
Add a wildcard entry to the agent, or check the name’s depth |
domain_not_verified |
422 | The hostname is not under a verified domain of the workspace | Verify the domain in Domains & addresses |
hostname_in_use |
409 | The hostname is in another open preview the token cannot use, or the names are in different previews | End that preview, or share the names separately |
scope_missing |
403 | The token lacks a scope the call needs, such as agents.names to turn a name on |
Create a token with that scope |
forbidden |
403 | The token’s member does not hold the permission | Ask an admin for the role |
validation_failed |
422 | A field is refused (param names it), such as a length under 15 minutes |
Fix the field |
limit_reached |
409 | A workspace limit, such as open previews or named viewers | End a preview, or raise the limit |
preview_ended |
409 | The preview ended (hostname endpoints) | Share again to open a new one |
The rest of the error contract (the error shape, rate limits, request_id) is in the
API guide.
Button artwork
Section titled “Button artwork”Two images for places that cannot run the HTML snippet, such as a README or a wiki:
| For | File |
|---|---|
| Light pages | share-with-houseguest-light.svg |
| Dark pages | share-with-houseguest-dark.svg |
The HTML button follows the page’s color scheme; add hg-light or hg-dark to the link to fix one. Its
styles are in share-button.css; copy them into your own stylesheet if
your pages load nothing from other sites. Keep the label as it is, Share with Houseguest™, and the door mark
in orange.
© 2026 Houseguest Technologies LLC. Houseguest™ is its trademark.7723 Tylers Place Blvd., Box #119, West Chester, OH 45069