Doc::CS API: Difference between revisions
m Protected "Doc::CS API" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
=== Curl === | === Curl === | ||
This example uses the <code>curl</code> command to access the api. | This example uses the <code>curl</code> command to access the api. Replace 'myservice' with the username of your service. | ||
Look up user information by Hokie ID | Look up user information by Hokie ID using username and password | ||
<code>curl -H 'Accept: application/json; indent=4' -u myservice https://api.cs.vt.edu/hokieids/99999999</code> | <code>curl -H 'Accept: application/json; indent=4' -u myservice https://api.cs.vt.edu/hokieids/99999999</code> | ||
Look up user information by Hokie ID using auth token | |||
<code>curl -H 'Accept: application/json; indent=4' -H 'Authorization: Token <my token text>' https://api.cs.vt.edu/hokieids/99999999</code> | |||
=== Python === | === Python === | ||
Line 26: | Line 29: | ||
uid = 1 | uid = 1 | ||
# Using username/password auth | |||
response = requests.get(base_url + str(uid) + '/', auth=HTTPBasicAuth('myservice', 'mypassword')) | response = requests.get(base_url + str(uid) + '/', auth=HTTPBasicAuth('myservice', 'mypassword')) | ||
# Using token auth | |||
response = requests.get(base_url + str(uid) + '/', headers={'Authorization': 'Token <my token text>'}) | |||
if response.status_code is 200: | if response.status_code is 200: | ||
data = response.json() | data = response.json() |
Latest revision as of 13:02, 20 October 2020
Overview
This service is in beta.
A REST api to access/update certain departmental information is available at https://api.cs.vt.edu
Authentication
Authentication is made with a unique username/password combination for each service needing access to the API. Access will be limited to the individual items need by the service.
Examples
Curl
This example uses the curl
command to access the api. Replace 'myservice' with the username of your service.
Look up user information by Hokie ID using username and password
curl -H 'Accept: application/json; indent=4' -u myservice https://api.cs.vt.edu/hokieids/99999999
Look up user information by Hokie ID using auth token
curl -H 'Accept: application/json; indent=4' -H 'Authorization: Token <my token text>' https://api.cs.vt.edu/hokieids/99999999
Python
A simple example using ptyhon
import requests from requests.auth import HTTPBasicAuth base_url = 'https://api.cs.vt.edu/hokieids/' uid = 1 # Using username/password auth response = requests.get(base_url + str(uid) + '/', auth=HTTPBasicAuth('myservice', 'mypassword')) # Using token auth response = requests.get(base_url + str(uid) + '/', headers={'Authorization': 'Token <my token text>'}) if response.status_code is 200: data = response.json() print(data['display_name']) else: print(response.text)