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:
- https://ucsb-cs156/proj-courses: A course search app
- https://ucsb-cs156/proj-dining: An app that shows dining commons menus and provides a way to leave reviews.
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:
- Navigate to https://developer.ucsb.edu/ in your web browser
- Click
Log in
orCreate an Account
(if you are not yet logged in, they both end up at the same place) -
Click the
Log in with UCSBNet id
button.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.
- An account is created for you automatically.
How to set up an API key
To set up an API key you create an “app”.
-
From home page, click Apps on top menu row
-
Click the
Add app
button: -
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.
Then scroll down so that you can see all of the check buttons for APIs, as shown in the image below.
- 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.)
The eight Auto-Approved APIs you want to select are:
-
When you’ve selected all of these, click the
Add app
button at the bottom of the page: -
You’ll be returned to the
Apps
page with a message like this one:You should then find your app in the list of apps, like this:
-
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:
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:
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
:
When you do, the modal will change to look like this. Click Close
:
You should now be able to click the GET
buttons on any of the API endpoints, and open up the Swagger interface:
You can then click the Try it out
button, which should give you the Execute
button:
After you do this, you can see the Response Json on the page:
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: