Slater New
« back to Blog

Javascript 101: Greenhouse API

Jared Malan
Director Of Technology
 @
Edgar Allan

We've used the following really useful script from Ben Parker several times. The code dynamically fetches job data from a Greenhouse API and displays it on a webpage.

First, take a look at the code here: https://slater.app/community_library/greenhouse-43bbc514-8155-4df6-9fb0-61b8efe41639.
Now, let's break down the code.

  1. Global Object (domElements)
    • This object holds references to important DOM elements (e.g., the main container, loading indicator, job filter dropdown).
  2. Fetch Data Function (fetchData)
    • This function retrieves data from a given URL and returns it in JSON format. It handles errors if the data cannot be fetched.
  3. Filter Jobs (jobFilter.onchange)
    • When the user changes the filter dropdown, this code shows or hides job sections based on the selected filter value.
  4. Initialize Job Data (initJob Function)
    • Displays a loading indicator.
    • Fetches department data from the API.
    • Creates sections for departments with jobs, adds them to the page, and populates the filter dropdown.
  5. Write Job Listings (writeJobs Function)
    • Fetches job data for each department.
    • Updates the page with job listings under the correct department sections.
    • Hides the loading indicator and displays the main content once all jobs are loaded.

How It Works

  1. Page Load: initJob is called to start the process.
  2. Data Fetching: Departments and jobs are fetched from the API.
  3. DOM Updates: Sections and job listings are dynamically created and added to the page.
  4. User Interaction: The filter dropdown lets users choose which job sections to view.

You may not need this code now, but we've found Greenhouse to be a very common tool that our clients use. So, maybe in the future. See if you can follow how the code works. We'll discuss topics found in this script in future emails.

Try it out for yourself

Sign up for a free trial and see if Slater is for you.

Share this post

We are building a first-class development experience that bridges together code and no-code.