polygon-misc

Polygon API Documentation

What’s new

Contents

How to download a problem or contest

Use HTTP POST-requests:

Introduction

To access Polygon API you just send a HTTP-request to address https://polygon.codeforces.com/api/{methodName} with method-specific parameters.

Most method calls return a JSON-object (if not specified otherwise) with three possible fields: status, comment and result.

Authorization

Using Polygon API requires authorization. To authorize, you will need an API key, which can be generated on settings page. Each API key has two parameters: key and secret. To use the key you must add following parameters to your request.

  1. apiKey - must be equal to key.
  2. time - current time in UNIX format (e.g., System.currentTimeMillis()/1000). If the difference between server time and time, specified in parameter, will be greater than 5 minutes, request will be denied.
  3. apiSig - signature to ensure that you know both key and secret. The first six characters of the apiSig parameter can be arbitrary. We recommend to choose them at random for each request. Let’s denote them as rand. The rest of the parameter is hexadecimal representation of SHA-512 hash-code of the following string: <rand>/<methodName>?param1=value1&param2=value2…&paramN=valueN#<secret> where (param_1, value_1), (param_2, value_2), …, (param_n, value_n) are all the request parameters (including apiKey, time, but excluding apiSig) with corresponding values, sorted lexicographically first by param_i, then by value_i.

Methods

problems.list

Returns a list of problems, available to the user, according to search parameters.

Parameters:

Returns:

A list of Problem objects.

problem.create

Create a new empty problem. Returns a created Problem.

Parameters:

Methods for problems

To access problem-specific API methods, add a problemId parameter to your request. The user must have access to the problem. Methods require at least READ access unless stated otherwise; problem.commitChanges, problem.saveNote and problem.buildPackage require WRITE access. problem.accesses requires effective WRITE or OWNER access, including access received through a user group. problem.setAccess requires direct WRITE or OWNER access; group access alone is insufficient. Administrators may use both access-management methods. Translators may use only methods explicitly marked as available to translators. If the problem has the pin code, add the pin parameter to your request.

The problem-specific methods available to translators are problem.info, problem.statements, problem.renderStatements, problem.saveStatement, problem.statementResources, problem.viewStatementResource and problem.saveStatementResource.

problem.accesses

Returns the problem’s direct access-control entries. Both users and user groups are returned; groups are not expanded into their members. The method does not calculate each user’s effective access.

The method requires effective WRITE or OWNER access and is not available to translators. Access received through a user group is sufficient for this read-only method. The access list is stored immediately at problem level and is not part of the working copy.

Parameters:

None besides the common problemId and optional pin parameters.

Returns:

A list of ProblemAccess objects sorted by login using case-sensitive string ordering.

For sample and example problems, only the owner entry is returned. Automatically created per-user READ entries of sample problems and the anonymous READ entry of example problems are intentionally omitted.

Example response:

{
  "status": "OK",
  "result": [
    {"login": "@editors", "accessType": "WRITE"},
    {"login": "alice", "accessType": "READ"},
    {"login": "owner", "accessType": "OWNER"}
  ]
}

problem.setAccess

Idempotently sets one user’s direct access to the problem. Changes take effect immediately: repository permissions and the problem modification time are updated, and problem.commitChanges is not required.

The method requires direct WRITE or OWNER access and is not available to translators. Effective WRITE or OWNER access received only through a user group is insufficient. Administrators may use the method.

Parameters:

Behavior:

A successful response has status OK and no result field:

{"status":"OK"}

The method returns HTTP 400 with status FAILED for an unknown user, an unsupported user-group login or accessType, insufficient direct access, an attempt to change ownership, a sample or example problem, an exceeded change rate limit, or an invalid required pin.

problem.info

Returns a ProblemInfo object.

problem.updateInfo

Update problem info. All parameters are optional.

Parameters:

If both the effective input and output file names are equal ignoring case, the method returns status “FAILED”.

problem.note

Returns problem note. This note is a problem-level user note and is not related to statement notes.

Parameters:

None

Returns:

A string - the problem note, or an empty string if no note is set.

problem.saveNote

Saves problem note. This method updates the stored problem note immediately; it does not modify the working copy and does not require problem.commitChanges.

Parameters:

problem.updateWorkingCopy

Updates working copy.

problem.discardWorkingCopy

Discards working copy.

problem.commitChanges

Commits problem changes. All parameters are optional.

Parameters:

Returns:

A CommitResult object. If there are no changes, the top-level status is “OK” and the result contains committed=false, conflictOccurred=false and message="No changes". If commit fails, the top-level status is “FAILED” and comment contains the failure message.

problem.statements

Returns a map from language to a Statement object for that language.

problem.renderStatements

Renders statements and tutorials from the current working copy. For each available statement language, the method returns independent HTML and PDF render results. Tutorials are returned only for languages where the current working copy has non-empty tutorial content.

The method requires READ access and is available to translators. If one HTML or PDF render fails or times out, the method still returns status “OK” and puts the error into that particular RenderResult. Each individual HTML/PDF render is limited to 1 minute.

If the whole request does not finish in 4 minutes, the method returns status “FAILED” with comment “Statement rendering did not finish in 4 minutes. Please repeat the request in 4 minutes.”

Parameters:

Returns:

A RenderStatements object.

problem.saveStatement

Update or create a problem’s statement. All parameters except for lang are optional.

Parameters:

problem.statementResources

Returns a list of statement resources for the problem.

Parameters:

None

Returns:

A list of File objects.

problem.viewStatementResource

Returns statement resource file. In case of success, this method does not return JSON, instead it returns the requested file with the corresponding mime-type set.

This method is available to translators.

Parameters:

problem.saveStatementResource

Add or edit statement resource file.

This method is available to translators.

Parameters:

problem.checker

Returns the name of the currently set checker.

problem.validator

Returns the name of the currently set validator.

problem.extraValidators

Returns an array containing the names of the currently set extra validators.

problem.interactor

Returns the name of the currently set interactor.

problem.validatorTests

Returns a list of validator tests for the problem.

Parameters:

None

Returns:

A list of ValidatorTest objects.

problem.saveValidatorTest

Add or edit validator test. Line breaks in passed testInput are normalized to CRLF without adding a trailing EOL, and EOL-equivalent inputs are equal for duplicate checks. Every successful save clears the previous run result. In case of editing, all parameters except for testIndex are optional. In case of adding, all parameters except for testIndex, testInput and testVerdict are optional.

Parameters:

problem.checkerTests

Returns a list of checker tests for the problem.

Parameters:

None

Returns:

A list of CheckerTest objects.

problem.saveCheckerTest

Adds or edits checker test. Line breaks in passed testInput, testOutput and testAnswer are normalized to CRLF without adding a trailing EOL, and EOL-equivalent values are equal for duplicate checks. Every successful save clears the previous run result. In case of editing, all parameters except for testIndex are optional. In case of adding, all parameters except for testIndex, testInput, testAnswer, testOutput and testVerdict are optional.

Parameters:

problem.files

Returns the list of resource, source and aux files. Method returns a JSON object with three fields: resourceFiles, sourceFiles and auxFiles, each of them is a list of File objects.

problem.solutions

Returns the list of Solution objects.

problem.viewFile

Returns resource, source or aux file. In case of success, this method does not return JSON, instead it returns plain view of the file with the corresponding mime-type set.

Parameters:

problem.viewSolution

Returns solution file. In case of success, this method does not return JSON, instead in returns plain view of the solution file.

Parameters:

problem.script

Returns script for generating tests. In case of success, this method does not return JSON, instead it returns plain view of the script.

Parameters:

problem.clearScript

Clears script for generating tests in the specified testset.

Parameters:

problem.tests

Returns tests for the given testset

Parameters:

Returns:

A list of Test objects.

problem.previewTests

Returns cached or currently available test previews for tests in the specified testset. If a preview is missing or stale, the method may start preview generation and return a TestPreview object without input and answer; repeat the request later to get generated data.

Parameters:

Returns:

A list of TestPreview objects.

problem.testInput

Returns generated test input. In case of success, this method does not return JSON, instead it returns plain view.

Parameters:

problem.testAnswer

Returns generated test answer. In case of success, this method does not return JSON, instead it returns plain view.

Parameters:

problem.setValidator

Update validator.

Parameters:

problem.setChecker

Update checker.

Parameters:

problem.setInteractor

Update interactor.

Parameters:

problem.saveFile

Add or edit resource, source or aux file. In case of editing, all parameters except for type and name are optional.

Parameters:

The parameters forTypes, stages, assets can be present only together (it means, all of them are absent or all of them are used at the same time). They can be used only for type=resource.

To delete ResourceAdvancedProperties of a resource file pass empty “forTypes=”.

problem.saveSolution

Add or edit solution. In case of editing, all parameters except for name are optional.

Parameters:

problem.editSolutionExtraTags

Add or remove testset or test group extra tag for solution.

Parameters:

problem.saveScript

Edit script.

Parameters:

problem.saveTest

Add or edit test. In case of editing, all parameters except for testset and testIndex are optional.

Parameters:

problem.deleteTest

Delete one or more tests from a testset.

The method first checks all requested tests and then deletes them. It returns “OK” only if every requested test was deleted. If at least one requested test can not be deleted during the pre-check, the method returns “FAILED” with a DeleteTestsResult object, comment “Some tests can not be deleted.” and does not delete any tests. DELETE_FAILED may occur after a successful pre-check during the actual deletion; if it occurs, the method returns comment “Some tests failed during deletion; problem state may be partially modified.” and some earlier tests may already have been deleted.

Parameters:

problem.setTestGroup

Set test group for one or more tests. It expects that for specified testset test groups are enabled.

Parameters:

problem.enableGroups

Enable or disable test groups for the specified testset.

Parameters:

problem.enablePoints

Enable or disable test points for the problem.

Parameters:

problem.enableTreatPointsFromCheckerAsPercent

Enable or disable treating points returned by checker as percents.

If enable is true while test points are disabled for the problem, the method returns status “FAILED”.

Parameters:

problem.viewTestGroup

Returns test groups for the specified testset.

Parameters:

Returns:

A list of TestGroup objects.

problem.saveTestGroup

Saves test group. Use if only to save a test group. If you want to create new test group, just add new test with such test group.

Parameters:

problem.viewTags

Returns tags for the problem.

Parameters:

None

Returns:

A list of strings - tags for the problem.

problem.saveTags

Saves tags for the problem. Existed tags will be replaced by new tags.

Parameters:

problem.viewGeneralDescription

Returns problem general description.

Parameters:

None

Returns:

A string - the problem general description.

problem.saveGeneralDescription

Saves problem general description.

Parameters:

problem.viewGeneralTutorial

Returns problem general tutorial.

Parameters:

None

Returns:

A string - the problem general tutorial.

problem.saveGeneralTutorial

Saves problem general tutorial.

Parameters:

problem.materials

Returns the publishable material configurations from the current working copy. The result is sorted by material name using case-sensitive string ordering. The response is not paginated and may be large.

The method requires READ access, is not available to translators and rejects a working copy with conflicts. It returns stored legacy configurations without applying the stricter validation used by problem.setMaterial; consequently, a returned material can contain an empty item or a reference that has become invalid.

Parameters:

None besides the common problemId and optional pin parameters.

Returns:

A list of Material objects. An empty list is returned when the problem has no materials.

problem.setMaterial

Idempotently creates, fully replaces, renames or removes one publishable material in the current working copy. The method requires READ access, is not available to translators and rejects a working copy with conflicts. It does not commit the working copy; call problem.commitChanges separately to create a revision.

Use an HTTP POST request and send the parameters in the request body. In particular, do not put items into a query string.

Parameters:

Behavior:

The input must be standard JSON: comments, single-quoted strings and unquoted names or values are rejected. The JSON schema is strict: unknown fields are rejected. Each item must have type and exactly one compatible array, tests or names. Each test selector must have a non-empty testset and exactly one mode: an existing integer index from 1 through Polygon’s current maximum test index (currently 1000), all=true, or asInput=true. The optional booleans all and asInput default to false. An all=true selector requires the testset to contain at least one test. asInput=true is accepted only in TEST_ANSWERS and requires an effective non-empty TEST_INPUTS selection for the same testset in this material. Every referenced test, file and solution must exist when the material is saved, and the material as a whole must contain at least one effective item.

A legacy material with an invalid reference can still be returned by problem.materials, but it cannot be replaced or renamed through this method until the submitted configuration is corrected. A real change rewrites the complete stored material list; fields unknown to this Polygon version can therefore be lost from every material file. A no-op does not perform this rewrite.

At most 60 problem.setMaterial attempts per minute are allowed for each calling user, in addition to the common API rate limit. Invalid and no-op calls that pass the common problem checks also consume this method-specific limit.

A successful response has status OK and no result field:

{"status":"OK"}

The method returns HTTP 400 with status FAILED for invalid parameters or JSON, missing referenced objects, a rename collision or stale rename request, conflicts, an invalid required pin, or an exceeded rate limit.

problem.packages

Returns a list of Package objects - list all packages available for the problem.

Parameters:

None

problem.package

Download a package as a zip-archive.

Parameters:

problem.buildPackage

Starts to build a new Package.

Parameters:

problem.cautions

Returns structured warnings and package-readiness issues for the problem. Also returns cached “Correction tips from AI”, if available.

The method inspects the current working copy. The four caution arrays common, statement, structure and issues are always present and may be empty. If both a missing checker/validator caution and the corresponding missing tests caution are detected, the redundant missing tests caution is omitted: NO_CHECKER_TESTS is omitted when NO_CHECKER is present, and NO_VALIDATOR_TESTS is omitted when NO_VALIDATOR is present.

AI tips are read from Polygon cache only; this method does not start new AI requests. If problem metadata cannot be built, the method returns status “FAILED”.

The method requires READ access and is not available to translators.

Parameters:

None

Returns:

A ProblemCautions object.

Contest methods

To access contest methods, you have to include contestId parameter in your request. If the contest has the pin code, you need to include the parameter pin in your request.

contest.problems

Returns a list of Problem objects - problems of the contest.

Return objects

Problem

Represents a polygon problem.

ProblemAccess

Represents one direct problem access-control entry returned by problem.accesses.

This object represents a stored direct entry, not a user’s computed effective access. Reviewer, supervisor, translator and email-notification flags are intentionally not returned.

ProblemInfo

Represents the problem’s general information.

CommitResult

Represents result of a problem.commitChanges call.

Statement

Represents a problem’s statement.

RenderStatements

Represents rendered statements and tutorials for the current working copy.

RenderedStatement

Represents rendered files for one language.

RenderResult

Represents one HTML or PDF render result.

File

Represents a resource, source or aux file.

ResourceAdvancedProperties

Represents special properties of resource files. Basically, they stand for compile- or run-time resources for specific file types and asset types. The most important application is IOI-style graders. Example: {“forTypes”:”cpp.*”,”main”:false,”stages”:[“COMPILE”],”assets”:[“SOLUTION”]}

Solution

Represents a problem solution.

Test

Represents a test for the problem.

DeleteTestsResult

Represents structured failure details for problem.deleteTest.

TestDeletionFailure

Represents a test that can not be deleted.

TestPreview

Represents preview data for one test.

TestGroup

Represents a test group in testset.

Material

Represents one publishable material configuration in the current working copy.

MaterialItem

Represents one group of files or tests included in a material.

An individual tests or names list may be empty for compatibility with materials created by the web editor. When saving through problem.setMaterial, at least one item in the complete material must be effective and non-empty.

MaterialTest

Represents one test selection inside a TEST_INPUTS or TEST_ANSWERS material item.

Exactly one selection mode must be effective: index, all=true, or asInput=true. On input to problem.setMaterial, omitted all and asInput fields default to false, and index may be omitted or null for the other two modes.

Package

Represents a package.

ValidatorTest

Represents a validator’s test for the problem.

CheckerTest

Represents a checker’s test for the problem.

ProblemCautions

Represents structured cautions for the problem.

Caution

Represents one problem caution.

PackageReadinessIssue

Represents a pre-package state issue collected by package validation.

problem.cautions uses fast package validation, so compile-only package checks are not included in packageReadinessIssues.

AiTips

Represents cached “Correction tips from AI” for the problem.

If disabled is true, statements is empty and validator and checker are absent. Internal UI confidence flags for AI tips are not returned.

StatementAiTip

Represents a cached AI correction tip for one statement language.

If processing is true, call problem.cautions later to check whether the suggestion has appeared.

SourceAiTip

Represents a cached AI review comment for a source file.