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 and problem.buildPackage require WRITE access. 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.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.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. 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. 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.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.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.

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.

TestPreview

Represents preview data for one test.

TestGroup

Represents a test group in testset.

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.