APIs: UCSB Developer API - Found at developer.ucsb.edu

The website https://developer.ucsb.edu offers API access to a variety of UCSB data sources.

Two UCSB legacy code projects make use of these APIs:

An API Key is required to use these APIs, and so is required to set up either of these apps.

Anyone with UCSB login credentials can create a UCSB developer account, and then create one or more API keys.

A few endpoints are “auto-approved”, meaning that anyone with a UCSB account can set up a key to access these endpoint. These are the only ones that we use in CMPSC 156.

These allow access to information that is, for the most part, already available on public facing websites. The API gives us programmatic access to that and avoids the need for “screen scraping”.

  • Course catalog listings
  • Dining commons menus
  • Translations of “codes” into “text” (e.g. translating "CMPSC" to "Computer Science" and "ARTHI" to "Art History".

Most other endpoints, however, because they expose potentially sensitive information, require “approval”, which you are unlikely to get (so I encourage you not to ask for it; if they start getting lots of requests, my concern is that they’ll just make the process more difficult, and that wouldn’t serve anyone well.)

The rest of this page explains:

  • How to set up an account
  • How to set up an API key
  • How to make use of “Try out an API page” (which will be familliar, since it uses Swagger, just like our code bases)
  • How to access these APIs from a Spring Boot backend
  • How to configure proj-courses and proj-dining for a UCSB_API_KEY on localhost and dokku

How to set up an account

To set up an account:

  1. Navigate to https://developer.ucsb.edu/ in your web browser
  2. Click Log in or Create an Account (if you are not yet logged in, they both end up at the same place)
  3. Click the Log in with UCSBNet id button.

    image

    Please don’t try applying to create a “Functional Account”. Those are only provided to staff and administrators as explained here, and there’s a whole bureaucratic process.

  4. An account is created for you automatically.

How to set up an API key

To set up an API key you create an “app”.

  1. From home page, click Apps on top menu row

    select-app

  2. Click the Add app button:

    click-add-app

  3. In the form that comes up, fill in the name and description. The name is the only required field, and the name is solely for documentation purposes. I suggest you choose a name that makes sense to you, such as the name of the repo you are doing your project in, but this can literally be anything you want.

    fill-in-form

    Then scroll down so that you can see all of the check buttons for APIs, as shown in the image below.

  4. Check exactly, and only, the buttons shown below. This gives you access to all of the auto-approved APIs (and only those.)
    • Checking fewer means some functions might not work.
    • Checking more will delay getting your credentials (while your access request is processed, and then inevitably, denied.)

    Selecting auto approved APIs

    The eight Auto-Approved APIs you want to select are:

  5. When you’ve selected all of these, click the Add app button at the bottom of the page:

    image

  6. You’ll be returned to the Apps page with a message like this one:

    image

    You should then find your app in the list of apps, like this:

    your-new-app

  7. To access your API key, click on the app name as shown in the image above. That will take you to page like this one:

    consumer-key

    On this page, the only information you need is the Consumer Key, which is circled. Click where it says Show key and the key will be revealed (a long sequence of letters and numbers).

    You can access this at any time; it isn’t a “one time reveal” like some of the secret values provided by Google and Github APIs. But for now, copy it so that you can paste it in the next step that we try.

Trying out an API

To try out an API navigate to any one of the eight API endpoints that are Auto Approved. You can use the navigation on the website, or one of the convenient links here. I suggest Student Record Code Lookups because it’s the easiest to understand.

Once you land on the API page, it will look familiar if you’ve used Swagger in your CMPSC 156 Spring Boot apps. Here’s an example page:

authorize button

What’s different is how you unlock the API so that you can “try it out”. You need to click the Authorize button indicated in the image above.

When you click this, you see the following modal pop up. Paste the “Consumer Key” value that you copied into this form, and click Authorize:

image

When you do, the modal will change to look like this. Click Close:

image

You should now be able to click the GET buttons on any of the API endpoints, and open up the Swagger interface:

image

You can then click the Try it out button, which should give you the Execute button:

image

After you do this, you can see the Response Json on the page:

image

You are invited to try out a few of the APIs from this list so that you get comfortable with using them.

Configuring proj-courses and proj-dining with values of the UCSB_API_KEY

If you’ve configured your app for Google OAuth, then you are familiar with how to:

  • Set values in the .env file for localhost
  • Set values using dokku config:set ... on dokku

The value of UCSB_API_KEY is set in exactly the same way; use the Consumer Key value explained above.

Sample Code

Here are links to some sample code for using the UCSB API in our Spring Boot apps:

proj-courses:

proj-dining: