Skip to content

API Reference

Giantpizzahead edited this page Aug 10, 2020 · 4 revisions

Most of the API calls return JSON data. Some require the secret key to be used (like submitting code); this secret key is defined in the environment variables (see Setup Instructions). Others do not need this key (like getting the list of problems).

No Key Required

GET /api/get_problem_list

Returns the list of problems that have a status of "up" on JudgeLite. This list will be in the following format:

{
  "groups": [
    {
      "id": "test_group",
      "name": "A Test Group",
      "problems": [
        {
          "id": "test1",
          "name": "Test Problem #1",
          "difficulty": "Beginner",
          "blurb": "The first test problem",
        }
      ]
    }
  ]
}

There may be multiple problems in a group, and there can be multiple groups as well.

Here is a list of the fields in a group:

  • id - The ID of the group.
  • name - The name of the group.
  • problems - An array of problems that are in the current group.

Here is a list of the fields in a problem:

  • id - The ID of the problem.
  • name - The name of the problem.
  • difficulty - The difficulty of the problem. If the problem doesn't have a difficulty value, this field will be an empty string.
  • blurb - A short description of the problem.

GET /api/get_problem_info/<problem_id>

Gets the problem info of the problem with ID <problem_id> (this is a parameter you'll have to fill in). For example, a GET request sent to /api/get_problem_info/test1 could return:

{
  "id": "test1",
  "name": "Test Problem #1",
  "difficulty": "Beginner",
  "max_score": 100,
  "memory_limit": 64,
  "time_limit": 2,
  "statement": "<p>The problem statement should go here.</p>",
  "bonus": "<p>The bonus problem statement should go here (if there is a bonus).</p>",
  "hints": "<p>A helpful hint should go here.</p>"
}

Here is a list of the fields returned:

  • id - The ID of the problem.
  • name - The name of the problem.
  • difficulty - The difficulty of the problem. If the problem doesn't have a difficulty value, this field will be an empty string.
  • max_score - The max score that could be achieved by solving this problem (not including bonus).
  • memory_limit - The memory limit for this problem.
  • time_limit - The time limit for this problem. (This is x1.5 for Java, x2 for Python).
  • statement - The problem statement, formatted in HTML and MathJax. If no problem statement is found, this field will be "No problem statement available.".
  • bonus - The bonus problem statement, formatted in HTML and MathJax. If no bonus problem statement is found, this field will be "No bonus available.".
  • hints - The hints for this problem, formatted in HTML and MathJax. If no hints are found, this field will be "No hints available.".

Warning: If you try to get the problem info of a problem that doesn't exist (or the problem does not have a status of "up"), this API request will instead return the following:

{
  "error": "Invalid problem ID!"
}

Make sure to account for this in your code.


GET /api/get_status/<job_id>

Gets the status of the submission with the ID of <job_id> (You'll have to fill in this parameter). For example, a GET request sent to /api/get_status/b757deae-318b-4cdb-b8c8-81e2732ae65c could return:

{
  "status": "done",
  "final_score": 20,
  "max_score": 100,
  "score": [20, 0],
  "is_bonus": [0, 1],
  "subtasks": [
    [
      ["AC", 10, 3.4],
      ["WA", 183, 11.7],
      ["TLE", 2000, 59.5],
      ["MLE", 505, 256.0],
      ["RE", 293, 121.9]
    ],
    [
      ["WA", 10, 4.2],
      ["SK", 0, 0]
    ]
  ]
}

To submit code, send a POST request to /api/submit with the content type multipart/form-data. Include the following fields:

  • problem_id - The ID of the problem that you're submitting a solution for.
  • type - The language that your code is written in. Should be one of "java", "cpp", or "python".
  • code - The file containing the submission's source code. Note that this is an actual file, not just a string representing the source code.
  • username - The username of the person who is submitting the code. If you don't need usernames, just set this to something like "guest".
  • secret_key - The secret key that is set using JudgeLite's SECRET_KEY environment variable. This makes sure that only servers you control can actually submit code.

The returned status code will be 200 if the submission was successful, and 400 if the submission failed. The returned repsonse will be JSON. It will have exactly two of the following entries:

  • status - Reports on whether or not the submission was successful. Will be either "success" or "fail".
  • error - Only present if the submission failed. Presents a user-friendly message of why the submission failed.
  • job_id - Only present if the submission succeeded. This is the unique ID value that was assigned to the submission. It is used to query the status of the submission (see below).

To get the status of a submission, send a GET request to /api/status/<job_id>, where job_id is the ID returned from the initial POST request. The returned status code will be 202 if the submission is still processing, and 200 if the submission has been fully evaluated (or an error occurred). The returned response will be JSON. It will have the following entries:

  • status - Contains the status of the submission. Will be one of "queued", "judging", "done", "compile_error", or "internal_error".

The following entries may or may not be available, depending on the returned status:

  • score - (judging, done) The current score of the submission for each subtask.
  • is_bonus - (judging, done) Whether or not each subtask is a bonus subtask (useful for changing how bonus verdicts are displayed).
  • subtasks - (judging, done) A list of subtasks. Each subtask has a list of test cases. Each test case is an array with 3 values: ['verdict', time, memory].
  • max_score - (judging, done, compile_error) The maximum score that a submission could get on a problem, excluding bonus points.
  • final_score - (done, compile_error) The final score that a submission recieved.
  • error - (compile_error, internal_error) If status is compiler_error, the error message that the compiler generated. Else, the error code for the internal error.

Clone this wiki locally