I want to access data provided by an API. How do I make a call to the API to get the data?
In order to access the data provided by an API, follow the steps below.
Get the Consumer Key and Secret
- Browse the documentation of the available APIs to help you select one
- Register your application
- Depending on the API you request access to, the approval may take a couple of days or be automatic
- Go to My Apps and click on the application you just registered
- Copy the "Consumer Key" and "Consumer Secret" for use in the section below (as client id and client secret respectively)
Make the API call
- HTTP request to get an access token:
curl -X POST --header "Content-Type: application/x-www-form-urlencoded;charset=utf-8" -d "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET" "https://api.oregonstate.edu/oauth2/token"
- HTTP to make a request to the API using the access token:
curl -X GET --header "Content-Type: application/x-www-form-urlencoded;charset=utf-8" --header "Authorization: Bearer ACCESS_TOKEN" "https://api.oregonstate.edu/<API-ENDPOINT>"