Draw your own voting interface
Use the embed script's headless client to read requests, vote, suggest and comment from any page you control.
Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.
Set up
The headless client draws nothing and needs no stylesheet. You pass your project slug and embed key to init, then read and write through VoteFirst.client.
Call init once, and read the board straight away.
It is the same object the widgets use, so a popup you open beside your own list agrees about who the visitor is.
Both values come from Share & Embed in the dashboard. The embed key is public by design, so it can sit in a page.
Put the script tag with your other scripts. Your own code often runs before it arrives, and the queue described further down makes that order harmless.
VoteFirst.init({ project: 'your-project-slug', key: 'your-embed-key' });
const board = await VoteFirst.client.board();
const page = await VoteFirst.client.features({ sort: 'trending', per_page: 5 });Read
board, features, feature, comments, changelog and release. Each one is a promise, and the parameters are the API's own.
Six read methods return the board, a request or a release.
A list resolves to items and meta, and meta says whether another page exists.
board returns the project with its boards, columns, display settings and theme. The answer is held for the life of the page, because every widget needs it, so pass refresh: true when you want a fresh copy.
features takes board, column, scope, status, tag, q, sort, page and per_page. feature returns one request in full, and comments takes a request id with its own paging. changelog lists published releases newest first, and release returns one release with its body and the requests inside it.
A list resolves to an object holding items and meta. meta carries page, per_page, total, total_pages and has_more, which is everything a Load more button needs.
let page = 1;
async function loadMore(list, button) {
const result = await VoteFirst.client.features({ sort: 'trending', per_page: 10, page });
for (const item of result.items) {
const row = document.createElement('li');
row.textContent = item.heading;
list.append(row);
}
page += 1;
button.hidden = result.meta.has_more === false;
}Vote
identity returns voted_feature_ids, the requests this visitor has already voted on. Read it once when the list loads.
Draw every vote button in the state the visitor left it in.
Voting twice rejects with already_exists, so a toggle needs that list.
identity gives you the voter_id, the kind of visitor, a display_name and voted_feature_ids. It mints an anonymous identity when the browser has none, and it does so only once however many callers ask in the same moment.
vote casts a vote and unvote takes it back. Both mint an identity first when this browser holds none, so there is nothing to call before the very first vote.
const me = await VoteFirst.client.identity();
let voted = me.voted_feature_ids.includes(feature.id);
button.setAttribute('aria-pressed', voted);
button.onclick = async function () {
if (voted) await VoteFirst.client.unvote(feature.id);
else await VoteFirst.client.vote(feature.id);
voted = voted === false;
button.setAttribute('aria-pressed', voted);
};Suggest and comment
suggest takes a heading and a description. comment takes a request id and a content body, and a parent_id turns it into a reply.
A suggestion and a comment are one call each.
likeComment and deleteComment cover the rest of a thread.
A suggestion follows the API's rule and waits in the review queue until you approve it. Show a thank you after it is sent, not a new card on the list.
likeComment likes a comment or takes the like back, and deleteComment removes a comment this visitor left. Your page can offer both without a second kind of account.
await VoteFirst.client.suggest({ heading: 'Dark mode', description: 'Easier on the eyes at night' });
await VoteFirst.client.comment(1234, { content: 'Same here', parent_id: 56 });Sign in
signIn takes a token your server signs, and from then on every vote and comment is recorded against that person.
Carry your own users across with signIn on every load.
The sign in is held in memory, so the page calls it each time it loads.
signIn reloads every widget on the page. A refused token leaves the visitor anonymous rather than stranded, and the call rejects with identity_invalid.
signOut drops the sign in, and the anonymous identity the browser held before comes back. forget clears that anonymous identity as well, which suits a shared computer. Votes already cast stay on the board under the identity that cast them.
The token itself needs a server to sign it. The guide on single sign on for a feedback board covers that part.
const token = await fetch('/api/votefirst-token').then((r) => r.text());
try {
await VoteFirst.client.signIn(token);
} catch (error) {
if (error.code === 'identity_invalid') console.warn('The visitor stays anonymous');
}Load order
window.vfq is a list of functions that run with the API as their argument, whether the script has loaded or not.
Queue your code so the script is free to arrive late.
A votefirst:ready event on the document does the same for code that prefers to listen.
Push a function onto the queue and move on. It leaves no listener to remove later, which is why the queue is the one to reach for.
Once the VoteFirst object exists the script has loaded, so ready is a shape and not a wait. config reports what init settled on, including the project and the base address the calls go to.
window.vfq = window.vfq || [];
window.vfq.push(function (VoteFirst) {
VoteFirst.init({ project: 'your-project-slug', key: 'your-embed-key' });
VoteFirst.client.features({ per_page: 3 }).then(function (page) {
console.log(page.meta.total, 'requests');
});
});Storage
config().persistent is false when the browser refuses local storage, and the identity then lives only for the page session.
Check persistent before you promise to remember anyone.
That visitor can still vote, and tomorrow they are somebody new.
A hardened profile and some private windows refuse local storage outright. Read persistent before a page claims that votes will be remembered, and keep the wording plain when it is false.
Everything the client rejects with is an Error that carries a code, a message, a status and a field. Branch on the code, as the guide on tracking widget events explains.
What the headless client gives you
Your own interface
Draw the list, the button and the thread the way the rest of your product draws things.
One visitor everywhere
Your own list and the script's popups share one identity, so a vote shows up in both.
No stylesheet to load
The client returns data only, so nothing in your page has to fight a foreign stylesheet.
Build a voting screen in four steps
Start by reading, and add writing last.
Call init
Pass the project slug and the embed key, then read the board.
List the requests
Call features with a sort and a page size, and draw the items.
Add the vote button
Start each button from voted_feature_ids, then call vote or unvote.
Sign users in
Call signIn on every load when your product has accounts.
What to know before you draw it yourself
- The client belongs to the web embed script. The Swift package has its own calls.
- A widget is less work than your own screen, so reach for the client only when the interface has to be yours.
- The sign in is not stored, so the page has to call signIn on every load.
- Signed sign in needs the Free or Pro plan, and Lite has none.
- Suggestions wait in the review queue, and the client cannot publish one.
Headless client questions
What is the headless client?
VoteFirst.client, the object every widget uses, exposed so your page can render its own interface.
Does it draw anything?
No. It returns data and needs no stylesheet.
How is a request the visitor already voted on found?
Read voted_feature_ids from identity and check whether the request id is in it.
What happens when a vote is cast twice?
The second call rejects with already_exists.
Is a sign in needed before the first vote?
No. Every write mints an anonymous identity first when the browser holds none.
What if the browser blocks local storage?
The identity lives in memory for the page session, and config().persistent reads false.
Can the client run before the script loads?
Yes. Push a function onto window.vfq and it runs once the script has arrived.
What does it cost?
The client ships in the embed script on every plan. Free holds one project and 100 votes, and past that a custom screen runs on Lite at $9/mo or Pro at $39/mo, after a 14 day trial with no card.
More ways to add a board
More on the embed script and its calls.
Make the screen yours
Begin on Free with one project. When a custom screen outgrows it, Lite is $9/mo and Pro is $39/mo, each after a 14 day trial with no card.