Tutor enables the API by default! 🎉 You can view the API documentation on your instance at https://your-edx/api-docs
, for example https://edx.ektu.kz/api-docs/
This page explains how to generate an OAuth token to access the API endpoints using Authorization Bearer
on Open edX. This method demonstrates one of the several ways of accessing the API.
This step is optional if you already have a user that you want to use for API access. We haven't tested it, but you can probably give specific permissions to a non-superuser account. There is some security risk to giving your API user admin rights.
tutor local createuser --staff --superuser api-user api@example.com
The first step is to create an OAuth API application.
Log into your LMS admin panel at https://your-edx/admin
.
Navigate to OAuth Applications
at https://your-edx/admin/oauth2_provider/application/
Press the Add Appliacation
button.
confidential
client credentials
Save the OAuth application.
Next, you will create an access token for the API user to access the API application
Navigate to Access tokens
at https://your-edx/admin/oauth2_provider/accesstoken/
.
Press the Add Access Token +
button.
Save to access token
Tip: Use the API Docs page to generate the API URL.
https://your-edx/api-docs
) and log in using your API user with admin rights.Find an API endpoint to test, such as a GET request for /course_modes/v1/courses/{course_id}/
Try it out
buttonExecute
buttonTake note of the Request URL
. You will need to use this URL when using curl
because it escapes the characters in the course ID
You can use curl
to access the API remotely using this syntax:
curl "<URL>" -H "Authorization: Bearer <ACCESS_TOKEN>"
Request URL
from the API-DOC testFor the /enrollment/v1/course/{course_id}
example above:
curl "https://edx.ektu.kz/api/course_modes/v1/courses/course-v1%3ACET%2BGW_01%2B2021_2022_FA/" -H "Authorization: Bearer super-secret-key"
Valid output: This response verifies that the bearer authorization is configured correctly.
[{"course_id":"course-v1:CET+GW_01+2021_2022_FA","mode_slug":"honor","mode_display_name":"Сертификат","min_price":0,"currency":"usd","expiration_datetime":null,"expiration_datetime_is_explicit":false,"description":null,"sku":null,"bulk_sku":null}]
Error encountered: (problem access token or credentials)
# Invalid token
curl "https://edx.ektu.kz/api/course_modes/v1/courses/course-v1%3ACET%2BGW_01%2B2021_2022_FA/" -H "Authorization: Bearer asdfasdfasfd"
{"error_code":"token_nonexistent","developer_message":"The provided access token does not match any valid tokens."}
# No credentials provided
curl "https://edx.ektu.kz/api/course_modes/v1/courses/course-v1%3ACET%2BGW_01%2B2021_2022_FA/"
{"detail":"Authentication credentials were not provided."}
References
Powered by Grav + with by Trilby Media.
© Copyright 2021, EKTU EdTech | CC BY 4.0 | Licensed under the Creative Commons Attribution 4.0 International license