REST API #776
cecilialau6776
started this conversation in
Show and tell
REST API
#776
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Spent the last day or so poking at/playing with the REST API, so I figured I'd share what I learned.
The REST API uses Django REST Framework.
Enabling REST API
PLUGIN_API=True
to yourcoldfront.env
file.coldfront migrate
to create the tables for tokens.systemctl restart gunicorn
).Our configuration has ColdFront behind Apache for OIDC auth, so we needed to add a few lines to our
ssl.conf
:Getting a Token
The enabled authentication classes are
TokenAuthentication
andSessionAuthentication
. I've not played withSessionAuthentication
, so I'm not sure how to use it.To get a token, you can:
coldfront drf_create_token <username>
will (re?)generate a token for that user.Using the API
Authenticate calls with the
Authentication: Token <token>
HTTP header.Examples:
Endpoints
I have not tested all of these. This is just a list compiled from
coldfront/plugins/api/urls.py
andcoldfront/plugins/api/views.py
, so it's possible/likely I'm missing a few endpoints/query parameters.Endpoints that return a list of objects appear to return all the objects the user has access to. For example, a regular user who is part of two projects would have those two projects returned when calling
/api/projects
. Superusers/staff would get all projects returned.The date format is what I tried and it worked. Other formats may also work.
Allocations
/api/allocations
/api/allocations/<pk>
Allocation Requests
/api/allocation-requests
created_before
: date (YYYY-M-D)created_after
: date (YYYY-M-D)/api/allocation-requests/<pk>
Allocation Change Requests
/api/allocation-change-requests
/api/allocation-change-requests/<pk>
Projects
/api/projects
allocations
: bool (defaultfalse
)false
, returnsnull
.project_users
: bool (defaultfalse
)false
, returnsnull
./api/projects/<pk>
allocations
: bool (defaultfalse
)false
, returnsnull
.project_users
: bool (defaultfalse
)false
, returnsnull
.Resources
/api/resources
/api/resources/<pk>
Users
/api/users/
username
: stringusername
. Must be exact.is_active
: boolis_active
.is_superuser
: boolis_superuser
.is_staff
: boolis_staff
./api/users/<pk>
Misc
Looks like there's no way to get project/allocation attributes nor their usages - this may become useful for us in the future, so I may make a PR for it, but I've higher-priority items right now (such as adding tags :D).
Looks like you get redirected without a trailing
/
- i.e.https://coldfront.rc.rit.edu/api/users
redirects tohttps://coldfront.rc.rit.edu/api/users/
.Looks like the API is only for getting information right now, with no way to create objects. Maybe this will be implemented in the future? I don't think our center needs it right now, so I'm unlikely to implement it myself.
Beta Was this translation helpful? Give feedback.
All reactions