
Previously, we created a component that could be embedded on any web page to display the releases of your design system, thus extending the reach of your design system's documentation. All thanks to the new zeroheight API. Let's utilize the API again, but this time to display the status of your components and other aspects of your design system on any web page.

Hey, it's me again, Dave, zeroheight's very own Web Components representative. In my last tutorial, we used the Styleguide releases endpoint to render a list of design system releases on a page, including their notes and links to that version of the design system.
This time around, though, we're going to use two endpoints in conjunction: the Pages endpoint and the Page Statuses endpoint.
As before, you'll need to ensure you have access to the API. Currently, the zeroheight API is only available for Enterprise customers. You can upgrade your plan here. You also may need to contact the administrator of your zeroheight instance to either get access or provide API credentials.
In addition, for the purposes of this tutorial, you'll need to be familiar with JavaScript and frontend technologies. However, if you're looking for something to copy and paste directly into your projects, you're welcome to make use of this example Web Component I've open-sourced on GitHub:
If you have good experience with JavaScript, feel free to snoop through the code. This is effectively what we're about to build, wrapped up into a Web Component. Check out my online guide, The Case For Web Components, to learn more.
Just like with any API request, you'll need the following credentials:
We have a handy guide in our Help Center to help you create a new authentication token for the API. When creating your authentication token, adjust the permissions as needed. For this guide, we'll only need read access. Don't forget to make a note of these details, as the Access Token will be hidden afterward for security reasons.
Your styleguide ID can be found in your browser address bar when viewing any page of your styleguide. URLs follow this pattern:
account.zeroheight.com/styleguide/s/STYLEGUIDEID/p/...
The characters that follow /styleguide/s/ and precede /p/ will be the ID of your styleguide. Make a note of this alongside your authentication token details.
Because we're using JavaScript, we can wrap these into an object of variables:
const zhAPI = {
'X-API-KEY': "API_KEY",
'X-API-CLIENT': "API_CLIENT",
styleguide: "STYLEGUIDE_ID"
};You can, of course, obscure these in production environments if you wish.
We'll once again be making use of the fetch() API to retrieve data from the zeroheight API. However, we'll be using two endpoints and merging that data together to get all the information we need to display the status of each page. First, let's get all the pages using the Pages endpoint:
const data = () => {
return fetch(
`https://zeroheight.com/open_api/v2/styleguides/${zhAPI.styleguide}/pages`,
{
method: "GET",
headers: zhAPI
}
)
.then((res) => res.json())
.then((json) => json.data.pages);
};
data().then(data => console.log(data));The above code has two parts. The first part gets all the pages using the Pages endpoint and formats the JSON response into data that can be used in JavaScript. The second part logs the data to the console. When running on a web page, the browser inspector can show the data being logged to the console.
{
"status": "success",
"data": {
"pages": [
{
"id": 5112407,
"name": "COLORS",
"created_at": "2023-10-27T08:24:42.978Z",
"updated_at": "2024-01-02T14:40:14.691Z",
"status": {
"request_id": "943e9c7c-3153-4a86-8c36-22cd01cf03af",
"reset_time": 1738149120,
"period": 30,
"limit": 30
}
}
]
}
}Here's a sample of what the API will return and what you'll see in the browser inspector. Expand the pages key to see all the page data. Note that status is mentioned a couple of times in this response, but this is the API status response status and not the page status.
If you compare the JavaScript, as well as the logged data, from getting pages to what was done in the previous article to get versions you'll notice how similar they are. The key difference is coming up, though, in terms of where we'll need to get the status of each page.
The only piece of data you need when using the Status endpoint is the ID of the page you want to check the status of. From there, you can form a JavaScript fetch request, just like we've been doing so for our other endpoints. Take a look at the code below.
const statusData = (id) => {
return fetch(
`
https://zeroheight.com/open_api/v2/pages/${id}/status
`,
{
method: "GET",
headers: zhAPI
}
)
.then((res) => res.json())
.then((json) => json.data);
};
statusData(5112407).then((data) => console.log(data));In the above example, the statusData function takes one parameter, the page id. That ID is then used within the request URL itself. The API then returns a small object of data that contains the name of the status and the status ID. At the very bottom of the code example, I'm using the function with a page ID I found in my example styleguide and logging the data returned.
Here's an example of what the API will return:
{
"status": "success",
"data": {
"id": "in_progress",
"name": "In progress"
}
}This is where things get interesting. The JavaScript fetch() is what we call a Promise. By default JavaScript will run code all at once, regardless of the ordered you intended it to (unless you're making use of callbacks). Promises are away for us to tell JavaScript to await for something to come back before going to the next step. This is ideal for API requests like we doing here as we don't know how long it'll take for the data to come back, either due to the users connection speed or the size of the data.
But we're already using fetch(), so we should be good right? Well not quite. We're waiting for the pages data to come back, and we're waiting for each status value to come back, but even with fetch we can't wait for all the statuses collectively. We need all the data before we render the content on the page.
Lets take a look at how we can roll all those requests into a single promise:
const data = () => {
return fetch(
`https://zeroheight.com/open_api/v2/styleguides/${zhAPI.styleguide}/pages`,
{
method: "GET",
headers: zhAPI
}
)
.then((res) => res.json())
.then((json) => {
return Promise.all(
json.data.pages.map(async (page) => {
const status = await fetch(
`https://zeroheight.com/open_api/v2/pages/${page.id}/status`,
{
method: "GET",
headers: zhAPI
}
)
.then((res) => res.json())
.then((json) => json.data);
return {
...page,
status
};
})
);
});
};
data().then(data => console.log(data));Let's step through this code:
Promise.allreturn each piece of page data, plus it's status data, as a single object (the ... is to adjust the format so it's easier to access the pieces of data on each page)Copy this into your project and test the results. You should see page data being logged in the following format:
{
id: 5112407,
name: "COLORS",
created_at: "2023-10-27T08:24:42.978Z",
updated_at: "2024-01-02T14:40:14.691Z",
status: {
id: "in_progress",
name: "In progress"
}
}Promises are complex to use and debug in the browser. I highly recommend carefully stepping through the code and logging the results as you go, even if you copy exactly the code I've shared above. Approach with patience
Now, with all this data combined into a usable format, we can turn that into visible content. To keep things simple, I'm going to render the page names and their status as a list. However, you may want to provide your design system consumers with more rich content in the form of a table, similar to the status table card in zeroheight.
data().then((data) => {
data.map((page) => {
document.querySelector("ol").innerHTML += `
<li>${page.name}: <strong>${page.status.name}</strong></li>
`;
});
});Here, I'm mapping through each page and appending it as an li element to an ol list. Each list item contains the page title and its current status.
And here's the finished example running on CodePen. While a bit more involved, this is a great way to share the status of your components and other design system aspects outside of zeroheight.
zh-status Web ComponentIn addition to it being plug-and-play, it's also a good reference point to look through alongside this article. We would love to hear from you on the things you're building with our API. Hit us up on LinkedIn, Bluesky, or wherever you're socializing online. We're always keen to see what you're building