zeroheight API Tutorial — Add Design System Releases to Any Website

David Darnes
Written by David Darnes
Dec 18, 2024

At zeroheight, we think your company's design system must be documented and, even more importantly, distributed. Documentation is how you educate your design and development teams about what's currently available in your design system. But what about outside of your design system? In this article, I'll share how you can use the new zeroheight API to embed release notes onto any page.

Demo showing the release history of a design system, from v0.0.1 to v0.1.0

What Is the New zeroheight API?

API stands for Application Programming Interface. In the same way humans interact with documentation to obtain information, machines interact with APIs to obtain information. This is how the web, apps, and, more recently, AI obtain data.

The zeroheight API provides a series of endpoints (places to get data from) which exposes the following:

For this tutorial, we'll use the Styleguide releases endpoint to get data about releases.

Prerequisites

Before continuing, you'll need to make sure 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. That being said, I've put together a fully working example that you can copy and drop into your projects:

This is effectively what we're about to build but wrapped up into a Web Component. Want to learn more about Web Components? Check out my online guide, The Case For Web Components, to learn more.

Setting Up

We have a handy guide in our Help Center to help you create a new authentication token for the API. Ensure to adjust the permissions as needed when creating your authentication token. For this guide, we'll only need read access. Don't forget to make a note of your Client ID and Access Token during setup, as your Access Token will be hidden after it's created.

The one other key needed is the ID of the styleguide you want to retrieve using the API. Navigate to your styleguide and use the address bar in your web browser to view the whole URL. It should follow a pattern that looks like this:

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.

For ease of use within a JavaScript file, it's best to add these to variables in an object:

const zhAPI = {
  'X-API-KEY': "API_KEY",
  'X-API-CLIENT': "API_CLIENT",
  styleguide: "STYLEGUIDE_ID"
};

In production environments, you might want to obscure these.

Returning Data With JavaScript

Thanks to modern JavaScript, we can make use of the fetch() API to fetch and return data from API endpoints such as the zeroheight versions endpoint.

const data = () => {
  return fetch(
    `https://zeroheight.com/open_api/v2/styleguides/${zhAPI.styleguide}/versions`,
    {
      method: "GET",
      headers: zhAPI
    }
  )
    .then((res) => res.json())
    .then((json) => json.data.versions);
};

The above code is a function that makes a request to the versions endpoint using the credentials we have supplied. After that, it returns the JSON-formatted response. More specifically, although a certain part of the response, versions.

Let's make use of this function to log the data returned in the console:

data().then(data => console.log(data));

If everything has gone according to plan, you should see a list of objects being logged into the browser console. Within the console, you'll also be able to expand sections of the logged data, in particular, the versions key, which will hopefully look like this:

{
  "status": "success",
  "data": {
    "versions": [
      {
        "id": 1234,
        "styleguide_id": 4321,
        "name": "V2",
        "created_at": "2024-10-30T09:40:45.636Z",
        "styleguide_name": "My Styleguide",
        "release_url": "https://zeroheight.com/4321/v/12abc",
        "project_id": 5678,
        "release_notes": "This is the V2 release"
      }
    ]
  }
}

This is where we'll be pulling the versions data from.

Displaying Data

Now that we have data coming back from the API, we can turn it into visible content. Due to it being an ordered list of the release history, I would advise adding an ordered list <ol> to the page and populate that element with the content.

Here's an example of how you might do that:

data().then((data) => {
  data.map((version) => {
    document.querySelector("ol").innerHTML += `
      <li><a href="${version.release_url}">${version.name}</a></li>
    `;
  });
});

In this example, I'm mapping through each version from the API and appending it to an ol element on the page as a list item li with an anchor link that takes the user to the latest release. Don't limit yourself, though. Using the returned data from the API, you can present the data however you wish.

See the Pen zeroheight API Releases Demo by David Darnes (@daviddarnes) on CodePen.

And with that, we're done! The above CodePen shows it working in action. It's impressive how, with a few lines of code, you can present your design system's release history on any page. Documentation access is vital to your design systems' success, and this is yet another item added to your toolbelt.

Strong design system delivery practices ensure those releases actually reach every team and stay in sync across products.

zh-releases Web Component

Looking for something that's more plug-and-play? The new zeroheight API is amazing for adding custom integrations, but sometimes you just want to drop some code in. That's why I created <zh-releases> Web Component. You can drop it into your frontend code, along with a script tag and your API credentials. We've added it to our GitHub org and published it on npm for easy installation with your JavaScript projects.

In 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

David Darnes
David Darnes
Try zeroheight
The design systems platform that keeps teams and agents in sync
Start for free
Share this post