You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
Version 1
Current »
tl;dr
All API requests need an API key. You can get an API key from using the API itself and confirming your email. Include the key in all requests as an X-API-KEY header. The live Swagger documentation is available here (https://openapi.data.uwaterloo.ca/api-docs/).
Getting an API key
- You'll need to get an API key to use for all your interactions with the Open Data API. You can get a key by using the Account endpoint (/v3/account).
POST your valid email address, project name and description, and project URL (such as to the website, app store, etc.) to the Register method (/v3/account/register). If successful you'll get a HTTP Status Code 200 response with your email in the body.
curl --request POST \
--url https://openapi.data.uwaterloo.ca/v3/account/register \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--form email=example@email.com \
--form 'project=1000th Best Project' \
--form uri=https://example.project.com
var client = new RestClient("https://openapi.data.uwaterloo.ca/v3/account/register");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"email\"\r\n\r\nexample@email.com", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
var data = new FormData();
data.append("email", "example@email.com");
data.append("project", "1000th Best Project");
data.append("uri", "https://example.project.com");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://openapi.data.uwaterloo.ca/v3/account/register");
xhr.send(data);
An email will arrive shortly to the email address you provided with your API key, and a Confirmation code.
POST to the Confirm method (v1/Account/Confirm) your email and Confirmation code to activate your API key.
curl --request POST \
--url https://openapi.data.uwaterloo.ca/v3/account/confirm \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--form email=example@email.com \
--form code=your_confirmation_code_from_email
var client = new RestClient("https://openapi.data.uwaterloo.ca/v3/account/confirm");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"email\"\r\n\r\nexample@email.com", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
var data = new FormData();
data.append("email", "example@email.com");
data.append("code", "your_confirmation_code_from_email");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://openapi.data.uwaterloo.ca/v3/account/confirm");
xhr.send(data);
- On success you'll get back a HTTP status code 200 response, or a 400 Bad Request in case of any failures. On success your account API key is confirmed and activated
- Get using!
Querying the API
- You'll need to include your API key as an 'X-API-KEY' header for all requests to the API.
As an example of querying the Subjects method.
curl --request GET \
--url https://openapi.data.uwaterloo.ca/v3/subjects \
--header 'x-api-key: your_api_key'
var client = new RestClient("https://openapi.data.uwaterloo.ca/v3/subjects");
var request = new RestRequest(Method.GET);
request.AddHeader("x-api-key", "your_api_key");
IRestResponse response = client.Execute(request);
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://openapi.data.uwaterloo.ca/v3/subjects");
xhr.setRequestHeader("x-api-key", "your_api_key");
xhr.send(data);
Troubleshooting
Most of the error messages should provide a hint as to what you need to fix. If you are encountering issues you can't work around please report the issue on the GitHub page (https://github.com/uWaterloo/OpenData/issues).