Building Blocks / Voice
Phone Hub (Inbound)
Pick a number, set hours, and route inbound calls.
Drop-in widget. Load
https://webforms.dropcowboy.com/latest/dropcowboy-phone-hub.min.jsand pass it a site token your server mints. Do not rebuild number search, business hours, or call routing forms; the widget already does it.Calling setup comes with the site token. Your page never configures SIP, STUN, or TURN servers; the script does.
When to use this vs REST
Use Phone Hub to let a user pick a number, set hours, and route inbound calls inside your app. Use REST to rent numbers or list lines from a backend.
Do not rebuild
- Number search and purchase.
- Business hours and inbound routing forms.
Drop-in
- On your server, trade your API key for a short-lived site token (the key needs
numbers:write):
// Your server. Browser code never sees KEY/SECRET.
app.post('/dropcowboy/token', async function (req, res) {
const r = await fetch('https://api-v2.dropcowboy.com/phone/public/embed/token', {
method: 'POST',
headers: {
'x-key': process.env.DC_KEY,
'x-secret': process.env.DC_SECRET,
'Content-Type': 'application/json'
},
body: JSON.stringify({ site_id: process.env.DC_SITE_ID, scope: ['phone:hub'], ttl_seconds: 900 })
});
const body = await r.json();
if (!r.ok) return res.status(r.status).json(body);
// The API wraps results in data. Hand the browser just the token.
res.json({ token: body.data.token, expires_at: body.data.expires_at });
});
Or test the mint with cURL:
# On your server: trade your API key (needs numbers:write) for a site token. 1 hour max.
curl -s -X POST https://api-v2.dropcowboy.com/phone/public/embed/token \
-H "x-key: $KEY" -H "x-secret: $SECRET" \
-H "Content-Type: application/json" \
-d '{"site_id":"YOUR_SITE_ID","scope":["phone:hub"],"ttl_seconds":900}'
- Load the script, init with the token, and call a method:
<script src="https://webforms.dropcowboy.com/latest/dropcowboy-phone-hub.min.js"></script>
<div id="phone-hub-slot"></div>
<script>
(async function () {
const minted = await fetch('/dropcowboy/token', { method: 'POST' }).then(function (r) { return r.json(); });
await DropCowboy.phoneHub.init({ token: minted.token });
DropCowboy.phoneHub.setTheme({ theme: 'LIGHT', primaryColor: '#009efb' });
DropCowboy.phoneHub.addErrorListener(function (event) {
console.error(event);
});
document.getElementById('rent-number').addEventListener('click', function () {
DropCowboy.phoneHub.openNumberPicker({ container: '#phone-hub-slot' });
});
})();
</script>
JS API / HTML tag
| Method | What it does |
|---|---|
init({ token }) |
Requires a site token with phone:hub. |
setTheme({ theme, primaryColor }) |
LIGHT/DARK plus accent. |
openHub({ container }) |
Opens the full inbound hub (numbers, hours, routes). |
openNumberPicker({ container }) |
Opens the DID search and rent flow. |
addErrorListener(fn) -> stop |
Fires on rent or update errors. |
close() |
Unmounts the hub. |
HTML tag:
<dc-phone-hub></dc-phone-hub>
Auth and scopes
Site token with the phone hub scope. Your API secret stays on your server.
Site token scope: phone:hub. Mint it with POST https://api-v2.dropcowboy.com/phone/public/embed/token using an API key with numbers:write. Tokens last up to one hour.
Limits
- Site tokens last at most one hour (the default). Mint a fresh one per page load or session; do not cache one across users.
- Calls and texts need a connected carrier (BYOC) and prepaid balance. Without them the mint returns 402 or 403 for telephony scopes.
- E911 and caller name (CNAM) are set in Drop Cowboy®, not in the widget.
Related REST
Routes are on https://api-v2.dropcowboy.com.
- POST /phone/public/numbers/rent - rent a number
- GET /phone/public/lines - list your numbers
- POST /phone/public/embed/token - mint the site token
Full reference: Embed site tokens.