Author: John Muschelli
Date: 2025-04-01

# Running the Glassdoor API

#### John Muschelli

#### 2025-04-01

# Glassdoor API Keys

In order to use the `glassdoor` package, you need an API key from Glassdoor

After that is done, you need to set up the API keys. The keys are grabbed using

    Sys.getenv("GLASSDOOR_PID")
    Sys.getenv("GLASSDOOR_PAT")

so you can set these either using `~/.Renviron` (will work generally) or your standard `.profile` or `.bash_profile` (if you work with command lines).

I recommend `.Renviron` as that works well with RStudio.

# Calling the API

The function `have_gd_tokens` is a little wrapper that allows you to check if you have both API keys set.

For example, the below code will look for `employers` and search for `pharmaceuticals` within them.

    library(glassdoor)
    if (have_gd_tokens()) {
    res = gd_api(
      action = "employers",
      other = NULL,
      version = 1,
      format = "json",
      q = "pharmaceuticals")
    }

The function used here is `gd_api` which is the workhorse function of the package. Generally, however, you probably want to use `gd_job_stats` or `gd_company`.

## Job Statistics

Most of the defaults in `gd_api` do not need to be set, but the User-Agent defaults to

    agent = gd_user_agent()

If you would like to change this, simply specify the `agent` argument in the `glassdoor` functions.

The job statistics specification can be found https://www.glassdoor.com/developer/jobsApiActions.htm.

    if (have_gd_tokens()) {
      res = gd_job_stats(
        job_title = "sales associate",
        returnJobTitles = TRUE)
        head(res$content$response$jobTitles, 3)
    }

    ## Warning in gd_api(version = "1.1", action = "jobs-stats", add_query = list(:
    ## Not Found (HTTP 404).

    ## NULL

## Employers

You can also access information from employers from `gd_company` or the duplicate function `gd_employer`:

    if (have_gd_tokens()) {
      res = gd_company(
        q = "dropbox")
      print(res$content$response$employers[[1]]$ceo)
    }

    ## $name
    ## [1] "Drew Houston"
    ##
    ## $title
    ## [1] "Founder and CEO"
    ##
    ## $numberOfRatings
    ## [1] 1091
    ##
    ## $pctApprove
    ## [1] 66
    ##
    ## $pctDisapprove
    ## [1] 34
    ##
    ## $image
    ## $image$src
    ## [1] "https://media.glassdoor.com/people/sqll/415350/dropbox-drew-houston.png"
    ##
    ## $image$height
    ## [1] 200
    ##
    ## $image$width
    ## [1] 200