Skip to content

Old API (v3.1.0 and below)

Jonathan Wu edited this page Jan 31, 2022 · 1 revision

Welcome

This page describes CTFOJ's API and how to use it. All endpoints labelled with Login required signify that they need to be authenticated.

To get started, generate an API key on the settings page.

Issues/Troubleshooting

Found a bug? File a bug report here

Authenticated Requests

All GET requests that require authentication should pass the api key as a query parameter. For example, /api/endpoint?key=00000000-0000-0000-0000-000000000000

All POST requests that require authentication should pass the api key as part of the post data.

Sample Markdown response

All Markdown responses will return a Markdown file containing the requested Markdown content.

Request (curl):

curl http://127.0.0.1:5000/api/problem/description/helloworld?key=00000000-0000-0000-0000-000000000000

Response:

Here's a sample Hello World problem. It can include [links](https://www.youtube.com/watch?v=dQw4w9WgXcQ) because it uses Markdown!

The flag for this problem is: `CTF{welcome_to_ctf_club}`

API Endpoints

GET /api/problem/description/<problem_id>

Login required

Usage

This endpoint is used to get the problem description with the specified problem id.

Response

Status Code Meaning Response Format
401 You are unauthorized; make sure you have included a valid session cookie in your request None
404 The problem referenced by the problem_id does not exist None
200 The request has succeeded Markdown

GET /api/problem/hints/<problem_id>

Login required

Usage

This endpoint is used to get any hints associated with the specified problem id. If there are no hints, the response body will be empty.

Response

Status Code Meaning Response Format
401 You are unauthorized; make sure you have included a valid session cookie in your request None
404 The problem referenced by the problem_id does not exist None
200 The request has succeeded Markdown

GET /api/problem/editorial/<problem_id>

Login required

Usage

This endpoint is used to get the editorial associated with the specified problem id. If the problem does not have an editorial, the response body will be empty.

Response

Status Code Meaning Response Format
401 You are unauthorized; make sure you have included a valid session cookie in your request None
404 The problem referenced by the problem_id does not exist None
200 The request has succeeded Markdown

GET /api/contest/<contest_id>/problem/description/<problem_id>

Login required

Usage

This endpoint is used to get the problem description with the specified contest & problem id.

Response

Status Code Meaning Response Format
401 You are unauthorized; make sure you have included a valid session cookie in your request None
404 The problem or contest referenced by the problem_id or contest_id does not exist None
200 The request has succeeded Markdown

GET /api/contest/<contest_id>/problem/hints/<problem_id>

Login required

Usage

This endpoint is used to get any hints associated with specified contest & problem id. If there are no hints, the response body will be empty.

Response

Status Code Meaning Response Format
401 You are unauthorized; make sure you have included a valid session cookie in your request None
404 The problem or contest referenced by the problem_id or contest_id does not exist None
200 The request has succeeded Markdown

GET /api/contest/<contest_id>

Login required

Usage

This endpoint is used to get the description of the contest with the specified contest id.

Response

Status Code Meaning Response Format
401 You are unauthorized; make sure you have included a valid session cookie in your request None
404 The contest referenced by the contest_id does not exist None
200 The request has succeeded Markdown

GET /api/announcement/<announcement_id>

Login special

Usage

This endpoint is used to get the contents of an announcement with the specified id. Authentication will be required if the site requires logging in to view announcements.

Response

Status Code Meaning Response Format
401 You are unauthorized None
404 The announcement referenced by the announcement_id does not exist None
200 The request has succeeded Markdown

GET /api/homepage

Login special

Usage

This endpoint is used to get the contents of the homepage, if it is enabled. If the homepage is disabled, admin authentication will be required.

Response

Status Code Meaning Response Format
403 The homepage is disabled and you are not an admin None
200 The request has succeeded Markdown

Undocumented API

These API endpoints are used internally, and should not be used.

  • POST /api/getkey