|
| 1 | +--- |
| 2 | +title: Submitty API Reference |
| 3 | + |
| 4 | +language_tabs: # must be one of https://git.io/vQNgJ |
| 5 | + - shell |
| 6 | + |
| 7 | +toc_footers: |
| 8 | + - <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a> |
| 9 | + |
| 10 | +includes: |
| 11 | + |
| 12 | +search: true |
| 13 | +--- |
| 14 | + |
| 15 | +# Introduction |
| 16 | + |
| 17 | +*Note: Student API is still a work in progress.* |
| 18 | + |
| 19 | +API provides an alternative way of interacting with Submitty. This is intended for students to be able to interact with Submitty without using the web UI. |
| 20 | + |
| 21 | +__*Note: All student requests require a parameter of 'user_id' for verification.*__ |
| 22 | + |
| 23 | +<aside class="warning"> |
| 24 | +The API is not formally versioned at this time, and its endpoints and their responses may change |
| 25 | +without warning. Use at your own risk! |
| 26 | +</aside> |
| 27 | + |
| 28 | +# Requests |
| 29 | + |
| 30 | +Submitty supports requests using the following two `content-types`: |
| 31 | + |
| 32 | +* application/json |
| 33 | +* application/x-www-form-urlencoded |
| 34 | + |
| 35 | +while anything involving files should use: |
| 36 | + |
| 37 | +* multipart/form-data |
| 38 | + |
| 39 | +All endpoints use the `/student_api` path off the base Submitty URL, followed by the specific endpoint |
| 40 | +for the API in question. |
| 41 | + |
| 42 | +# Responses |
| 43 | + |
| 44 | +> Example of a `success` JSON response: |
| 45 | +
|
| 46 | +```json |
| 47 | +{ |
| 48 | + "status": "success", |
| 49 | + "data": null |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +> Example of a `fail` JSON response: |
| 54 | +
|
| 55 | +```json |
| 56 | +{ |
| 57 | + "status": "fail", |
| 58 | + "message": "Gradeable does not exist." |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +All API responses will be returned as `application/json` and conform to a modified |
| 63 | +version of the [JSend specification](https://labs.omniti.com/labs/jsend). A response |
| 64 | +returned from the server is expected to be one of the following three response types. |
| 65 | + |
| 66 | +| Type | Description | Required Keys | Optional Keys | |
| 67 | +|---------|-----------------------------------------------------------------------------------------------------|----------------|---------------| |
| 68 | +| success | All went well, and (usually) some data was returned | status, data | | |
| 69 | +| fail | There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied | status, message | data | |
| 70 | +| error | An error occurred in processing the request, i.e. an exception was thrown | status, message | data, code | |
| 71 | + |
| 72 | +# Authentication |
| 73 | + |
| 74 | +```shell |
| 75 | +# With shell, you can just pass the correct header with each request |
| 76 | +curl "student_api_endpoint_here" |
| 77 | + -H "Authorization: my_token" |
| 78 | +``` |
| 79 | + |
| 80 | +> Make sure to replace `my_token` with your API token, or the API will return JSON like this: |
| 81 | +
|
| 82 | +```json |
| 83 | +{ |
| 84 | + "status": "fail", |
| 85 | + "message": "Unauthenticated access. Please log in." |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +Submitty uses [JSON Web Tokens](https://jwt.io/) to allow access to the API. You can obtain your API token through the following endpoint. |
| 90 | + |
| 91 | +Kittn expects for the API token to be included in all API requests to the server in a header that looks like the following: |
| 92 | + |
| 93 | +`Authorization: my_token` |
| 94 | + |
| 95 | +<aside class="notice"> |
| 96 | +You must replace <code>my_token</code> with your personal API token. |
| 97 | +</aside> |
| 98 | + |
| 99 | +## Get Token |
| 100 | + |
| 101 | +```shell |
| 102 | +curl -X POST \ |
| 103 | + <base_url>/student_api/token \ |
| 104 | + -F user_id=student \ |
| 105 | + -F password=student |
| 106 | +``` |
| 107 | + |
| 108 | +> The above command returns JSON structured like this: |
| 109 | +
|
| 110 | +```json |
| 111 | +{ |
| 112 | + "status": "success", |
| 113 | + "data": { |
| 114 | + "token": "a long string" |
| 115 | + } |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +Note that every time you request a new token, the previous token will be invalidated. |
| 120 | + |
| 121 | +### HTTP Request |
| 122 | + |
| 123 | +`POST /student_api/token` |
| 124 | + |
| 125 | +### Parameters |
| 126 | + |
| 127 | +Parameter | Description |
| 128 | +--------- | ----------- |
| 129 | +user_id | User's unique ID |
| 130 | +password | User's password |
| 131 | + |
| 132 | +## Invalidate Token |
| 133 | + |
| 134 | +```shell |
| 135 | +curl -X POST \ |
| 136 | + <base_url>/student_api/token/invalidate \ |
| 137 | + -F user_id=student \ |
| 138 | + -F password=student |
| 139 | +``` |
| 140 | + |
| 141 | +The endpoint invalidates the token you requested before. |
| 142 | + |
| 143 | +### HTTP Request |
| 144 | + |
| 145 | +`POST /student_api/token/invalidate` |
| 146 | + |
| 147 | +### Parameters |
| 148 | + |
| 149 | +Parameter | Description |
| 150 | +--------- | ----------- |
| 151 | +user_id | User's unique ID |
| 152 | +password | User's password |
| 153 | + |
| 154 | +# Gradeables |
| 155 | + |
| 156 | +## Get score |
| 157 | + |
| 158 | +```shell |
| 159 | +curl -X GET \ |
| 160 | + <base_url>/student_api/<term>/<course>/gradeable/<gradeable_id>/score?user_id=<user_id> |
| 161 | + |
| 162 | +``` |
| 163 | +> Possible responses: |
| 164 | +
|
| 165 | +```json |
| 166 | +{ |
| 167 | + "status": "success", |
| 168 | + "data": { |
| 169 | + "score": 0 |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | +```json |
| 174 | +{ |
| 175 | + "status": "fail", |
| 176 | + "message": "Gradeable does not exist" |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +The endpoint returns the score of an autograded gradeable. |
| 181 | + |
| 182 | +### HTTP Request |
| 183 | + |
| 184 | +`GET /student_api/<term>/<course>/gradeable/<gradeable_id>/score?user_id=<user_id>` |
| 185 | + |
| 186 | +### Parameters |
| 187 | + |
| 188 | +Parameter | Description |
| 189 | +--------- | ----------- |
| 190 | +user_id | User's unique ID |
| 191 | + |
| 192 | +## Submit VCS Gradeable |
| 193 | + |
| 194 | +```shell |
| 195 | +curl -X POST \ |
| 196 | + <base_url>/student_api/<term>/<course>/gradeable/<gradeable_id>/upload\ |
| 197 | + -F user_id=student \ |
| 198 | + -F vcs_checkout=true |
| 199 | +``` |
| 200 | +> Possible responses: |
| 201 | +
|
| 202 | +```json |
| 203 | +{ |
| 204 | + "status": "success", |
| 205 | + "data": "Successfully uploaded version {#} for {Gradeable Title}" |
| 206 | +} |
| 207 | +``` |
| 208 | +```json |
| 209 | +{ |
| 210 | + "status": "fail", |
| 211 | + "message": "Invalid gradeable id '{Gradeable ID}'" |
| 212 | +} |
| 213 | +``` |
| 214 | +```json |
| 215 | +{ |
| 216 | + "status": "fail", |
| 217 | + "message": "Student API for upload only supports VCS gradeables" |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | + |
| 222 | +The endpoint requests for a VCS gradeable to be submitted. |
| 223 | + |
| 224 | +### HTTP Request |
| 225 | + |
| 226 | +`GET /student_api/<term>/<course>/gradeable/<gradeable_id>/upload` |
| 227 | + |
| 228 | +### Parameters |
| 229 | + |
| 230 | +Parameter | Description |
| 231 | +--------- | ----------- |
| 232 | +user_id | User's unique ID |
| 233 | + |
0 commit comments