This document describes Sphere Engine Problems web service. It is explained here how the methods should be used and
how to interpret data returned by them. All URLs referenced in the documentation have the base
https://<customer_id>.problems.sphere-engine.com/api/v3.
Functionality
Sphere Engine Problems API allows you to:
create and modify problems, including:
description,
general settings,
test cases (model input, model output, judge),
master judge,
submit a solution to the problem with one of more than 80 languages,
run the program with model input data on the server-side,
download results of the execution (correctness status, execution time, consumed memory and much more technical
details).
The webservice
All API URLs listed in this document are relative to the https://<customer_id>.problems.sphere-engine.com/api/v3/ link called an endpoint. For example, the /test API call is reachable at https://<customer_id>.problems.sphere-engine.com/api/v3/test?access_token=<access_token>.
The Sphere Engine Problems API is a RESTful API. This implies the following:
API calls should be made with HTTP requests (GET, POST, etc.),
successes are represented by the 2xx codes,
errors are represented by 4xx and 5xx codes,
error code from 4xx group represents client errors,
error code from 5xx group represents connection or server error.
Requests
Request data is passed to the API by posting parameters to the API endpoints. To communicate with API endpoint you can
use any HTTP client/library. Each function takes at least one parameters - the access_token. For every GET and
DELETE request parameters have to be submitted in the query (i.e., url). For POST and PUT request you can send
parameters in the two possible ways:
as a FORM (i.e., Content-Type: application/x-www-form-urlencoded),
as a JSON (i.e., Content-Type: application/json).
The documentation for each API call will contain more details on the parameters accepted by the call.
Responses
Each response has two components: HTTP Status Code and JSON-encoded message.
The RESTful API uses HTTP response code to communicate the success or error. Here is the general list of possible
codes for Sphere Engine Compilers API.
Value
Interpretation
200
success
201
success (for creation methods)
400
bad request (invalid parameters)
401
unauthorized access (missing or incorrect access token)
403
forbidden access (referring to foreign or secured content)
404
non existing content (submission or compiler)
5xx
server side problem
Status code
A status parameter returned with submission details (i.e., using GET /submissions/:id API method) requires further
explanation.
The status specifies the stage of the program's execution. We can divide the possible values of statuses into two
separate groups.
Statuses from the first group are called transitional statuses. All of them are used during the execution of the
submission.
Value
Description
Meaning
<0
waiting for compilation
the submission awaits execution in the queue
1,2
compilation
the program is being compiled
3
running
the program is being executed
4
compilation
the judge is being compiled
5
running
the judge is being executed
6
compilation
the master judge is being compiled
7
running
the master judge is being executed
8
testing
the program is being tested
Statuses from the second group are called terminal or final statuses. One of these statuses is set at the end of
the execution of the submission.
Value
Description
Meaning
11
compilation error
the program could not be executed due to compilation error
12
runtime error
the program finished because of the runtime error, for example: division by zero, array index out of bounds, uncaught exception
13
time limit exceeded
the program haven't stopped before the time limit
14
wrong answer
program did not solve the problem
15
success
submission is accepted as a correct solution
17
memory limit exceeded
the program tried to use more memory than it is allowed to
20
internal error
some unexpected problem occurred
21
judge error
test case judge or master judge error
22
problem error
problem configuration error
It's a common practice to implement the following scenario for waiting for execution:
1. submit source code,
1. wait 5 seconds,
1. retrieve submission details,
1. (optional) present current status to the user,
1. if the status <= 8 go back to step (2),
1. (optional) present all execution details to the user.
The following diagram presents the idea of this algorithm:
Client libraries
There are client libraries available for the following programming languages:
stdout data, truncated to 5000 characters; please note that this field should serve debugging purposes only, it shouldn't be used to assess submission correctness (use proper judges and the result.status field for that)
Creates a new submission. Note that every usage of this method decreases submissions pool for your account.
If you want to create a submission with many files see: multi-file mode.
package problems.submissions;
/**
* Example presents error handling for createSubmission() API method
*/
import com.SphereEngine.Api.ProblemsClientV3;
import com.SphereEngine.Api.Exception.NotAuthorizedException;
import com.SphereEngine.Api.Exception.NotFoundException;
import com.SphereEngine.Api.Exception.BadRequestException;
import com.SphereEngine.Api.Exception.ClientException;
import com.SphereEngine.Api.Exception.ConnectionException;
import com.google.gson.JsonObject;
public class createSubmission
{
public static void main(String[] args)
{
ProblemsClientV3 client = new ProblemsClientV3(
"<access_token>",
"<endpoint>");
String problemCode = "TEST";
String source = "<source code>";
Integer compiler = 11; // C language
try {
JsonObject response = client.createSubmission(problemCode, source, compiler);
} catch (NotAuthorizedException e) {
System.out.println("Invalid access token");
} catch (NotFoundException e) {
// aggregates three possible reasons of 404 error
// non existing problem, compiler or user
System.out.println("Non existing resource (problem, compiler or user), details available in the message: " + e.getMessage());
} catch (BadRequestException e) {
System.out.println("Empty source code");
} catch (ClientException e) {
System.out.println(e.getMessage());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
}
}
<?php
/**
* Example presents error handling for createSubmission() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once('../../../../vendor/autoload.php');
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$source = '<source code>';
$nonexistingCompiler = 99999;
try {
$response = $client->createSubmission($problemCode, $source, $nonexistingCompiler);
// response['id'] stores the ID of the created submission
} catch (SphereEngineResponseException $e) {
if ($e->getCode() == 401) {
echo 'Invalid access token';
} elseif ($e->getCode() == 404) {
// aggregates three possible reasons of 404 error
// non existing problem, compiler or user
echo 'Non existing resource (problem, compiler or user), details available in the message: ' . $e->getMessage();
} elseif ($e->getCode() == 400) {
echo 'Empty source code';
}
}
"""
Example presents error handling for submissions.create() API method
"""
from sphere_engine import ProblemsClientV3
from sphere_engine.exceptions import SphereEngineException
# define access parameters
accessToken = '<access_token>'
endpoint = '<endpoint>'
# initialization
client = ProblemsClientV3(accessToken, endpoint)
# API usage
problemCode = 'TEST'
source = '<source code>'
nonexistingCompiler = 99999;
try:
response = client.submissions.create(problemCode, source, nonexistingCompiler)
# response['id'] stores the ID of the created submission
except SphereEngineException as e:
if e.code == 401:
print('Invalid access token')
elif e.code == 404:
# aggregates three possible reasons of 404 error
# non existing problem, compiler or user
print('Non existing resource (problem, compiler or user), details available in the message: ' + str(e))
elif e.code == 400:
print('Empty source code')
var request = require('request');
// define access parameters
var accessToken = '<access_token>';
var endpoint = '<endpoint>';
// define request parameters
var submissionData = {
problemCode: 'EXAMPLE',
compilerId: 11,
source: '<source_code>'
};
// send request
request({
url: 'https://' + endpoint + '/api/v3/submissions?access_token=' + accessToken,
method: 'POST',
form: submissionData
}, function (error, response, body) {
if (error) {
console.log('Connection problem');
}
// process response
if (response) {
if (response.statusCode === 201) {
console.log(JSON.parse(response.body)); // submission data in JSON
} else {
if (response.statusCode === 401) {
console.log('Invalid access token');
}
if (response.statusCode === 400) {
console.log('Empty source code');
}
if (response.statusCode === 404) {
console.log('Problem, compiler or user does not exist');
}
}
}
});
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace csharpexamples {
public class createSubmission {
public static void Main(string[] args) {
// define access parameters
string endpoint = "<endpoint>";
string accessToken = "<access_token>";
try {
WebClient client = new WebClient ();
// define request parameters
NameValueCollection formData = new NameValueCollection ();
formData.Add("problemCode", "EXAMPLE");
formData.Add("source", "<source_code>");
formData.Add("compilerId", "11");
// send request
byte[] responseBytes = client.UploadValues ("https://" + endpoint + "/api/v3/submissions?access_token=" + accessToken, "POST", formData);
string responseBody = Encoding.UTF8.GetString(responseBytes);
// process response
Console.WriteLine(responseBody);
} catch (WebException exception) {
WebResponse response = exception.Response;
HttpStatusCode statusCode = (((HttpWebResponse)response).StatusCode);
// fetch errors
if (statusCode == HttpStatusCode.Unauthorized) {
Console.WriteLine("Invalid access token");
}
if (statusCode == HttpStatusCode.BadRequest) {
Console.WriteLine("Empty source code");
}
if (statusCode == HttpStatusCode.Forbidden) {
Console.WriteLine("Compiler not available");
}
if (statusCode == HttpStatusCode.NotFound) {
Console.WriteLine("Problem, compiler or user not found");
}
response.Close();
}
}
}
}
require 'net/http'
require 'uri'
require 'json'
# define access parameters
endpoint = "<endpoint>"
access_token = "<access_token>"
# define request parameters
submission_data = {
"problemCode" => 'EXAMPLE',
"compilerId" => "11",
"source" => '<source_code>'
};
# send request
uri = URI.parse("https://" + endpoint + "/api/v3/submissions?access_token=" + access_token)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri);
request.set_form_data(submission_data)
begin
response = http.request(request)
# process response
case response
when Net::HTTPCreated
puts JSON.parse(response.body)
when Net::HTTPUnauthorized
puts "Invalid access token"
when Net::HTTPBadRequest
puts "Empty source code"
when Net::HTTPForbidden
puts "Compiler not available"
when Net::HTTPNotFound
puts "Problem, compiler or user not found"
end
rescue => e
puts "Connection error"
end
Response example
{
"id": 42
}
GET
/submissions?access_token=<access_token>
Returns information about submissions. Results are sorted ascending by id.
Request parameters
Name
Located in
Type
Description
access_token *
query
string
access token
ids *
query
string
ids of submissions separated by comma, maximum 20 ids
package problems.problems;
/**
* Example presents usage of the successful createProblem() API method
*/
import com.SphereEngine.Api.ProblemsClientV3;
import com.SphereEngine.Api.Exception.NotAuthorizedException;
import com.SphereEngine.Api.Exception.NotFoundException;
import com.SphereEngine.Api.Exception.BadRequestException;
import com.SphereEngine.Api.Exception.ClientException;
import com.SphereEngine.Api.Exception.ConnectionException;
import com.google.gson.JsonObject;
public class createProblem
{
public static void main(String[] args)
{
ProblemsClientV3 client = new ProblemsClientV3(
"<access_token>",
"<endpoint>");
String code = "EXAMPLE";
String name = "Example problem";
try {
JsonObject response = client.createProblem(code, name);
// response.get("id") stores the ID of the created problem
} catch (NotAuthorizedException e) {
System.out.println("Invalid access token");
} catch (NotFoundException e) {
System.out.println("Masterjudge does not exist");
} catch (BadRequestException e) {
// aggregates four possible reasons of 400 error
// empty problem code, empty problem name, not unique problem code, invalid problem code
System.out.println("Bad request (empty problem code, empty problem name, not unique problem code, invalid problem code), details available in the message: " + e.getMessage());
} catch (ClientException e) {
System.out.println(e.getMessage());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
}
}
<?php
/**
* Example presents error handling for createProblem() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once('../../../../vendor/autoload.php');
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$code = "EXAMPLE";
$name = "Example problem";
try {
$response = $client->createProblem($code, $name);
// response['id'] stores the ID of the created problem
} catch (SphereEngineResponseException $e) {
if ($e->getCode() == 401) {
echo 'Invalid access token';
} elseif ($e->getCode() == 400) {
// aggregates four possible reasons of 400 error
// empty problem code, empty problem name, not unique problem code, invalid problem code
echo 'Bad request (empty problem code, empty problem name, not unique problem code, invalid problem code), details available in the message: ' . $e->getMessage();
} elseif ($e->getCode() == 404) {
echo 'Masterjudge does not exist';
}
}
"""
Example presents error handling for problems.create() API method
"""
from sphere_engine import ProblemsClientV3
from sphere_engine.exceptions import SphereEngineException
# define access parameters
accessToken = '<access_token>'
endpoint = '<endpoint>'
# initialization
client = ProblemsClientV3(accessToken, endpoint)
# API usage
code = 'EXAMPLE'
name = 'Example problem'
try:
response = client.problems.create(code, name)
# response['id'] stores the ID of the created problem
except SphereEngineException as e:
if e.code == 401:
print('Invalid access token')
elif e.code == 400:
# aggregates four possible reasons of 400 error
# empty problem code, empty problem name, not unique problem code, invalid problem code
print('Bad request (empty problem code, empty problem name, not unique problem code, invalid problem code), details available in the message: ' + str(e))
elif e.code == 404:
print('Masterjudge does not exist')
var request = require('request');
// define access parameters
var accessToken = '<access_token>';
var endpoint = '<endpoint>';
// define request parameters
var problemData = {
name: 'Example',
code: 'EXAMPLE'
};
// send request
request({
url: 'https://' + endpoint + '/api/v3/problems?access_token=' + accessToken,
method: 'POST',
form: problemData
}, function (error, response, body) {
if (error) {
console.log('Connection problem');
}
// process response
if (response) {
if (response.statusCode === 201) {
console.log(JSON.parse(response.body)); // problem data in JSON
} else {
if (response.statusCode === 401) {
console.log('Invalid access token');
}
if (response.statusCode === 400) {
console.log('Empty name, empty code, not unique code or invalid code');
}
if (response.statusCode === 404) {
console.log('Masterjudge does not exist');
}
}
}
});
Response example
{
"code": "PROBLEMCODE"
}
GET
/problems/:code?access_token=<access_token>
Retrieves an existing problem
Request parameters
Name
Located in
Type
Description
access_token *
query
string
access token
code *
path
string
problem code
shortBody
query
boolean
whether shortened body should be returned, default: false
Response HTTP Code
Code
Description
200
success
401
unauthorized access
403
access denied
404
problem not found
Success Response
Field
Type
Description
code
string
problem code
name
string
problem name
body
string
problem description
type
string
type of the problem, binary|min|max
interactive
boolean
interactive problem flag
shortBody
string
shortened problem description (present only if shortBody = true)
masterjudge.id
integer
master judge id
masterjudge.name
string
master judge name
masterjudge.uri
string
master judge uri
testcases[].number
integer
test case number
testcases[].active
boolean
if test is active
lastModifiedBody
integer
timestamp of the last modification date of problem name or problem description
lastModifiedSettings
integer
timestamp of the last modification date of problem settings (type, interactivity, master judge, active test cases,
new test cases, updated test cases)
package problems.problems;
/**
* Example presents usage of the successful updateProblem() API method
*/
import com.SphereEngine.Api.ProblemsClientV3;
import com.SphereEngine.Api.Exception.NotAuthorizedException;
import com.SphereEngine.Api.Exception.NotFoundException;
import com.SphereEngine.Api.Exception.ForbiddenException;
import com.SphereEngine.Api.Exception.BadRequestException;
import com.SphereEngine.Api.Exception.ClientException;
import com.SphereEngine.Api.Exception.ConnectionException;
import com.google.gson.JsonObject;
public class updateProblem
{
public static void main(String[] args)
{
ProblemsClientV3 client = new ProblemsClientV3(
"<access_token>",
"<endpoint>");
String newProblemName = "New example problem name";
try {
JsonObject response = client.updateProblem("EXAMPLE", newProblemName);
} catch (NotAuthorizedException e) {
System.out.println("Invalid access token");
} catch (ForbiddenException e) {
System.out.println("Access to the problem is forbidden");
} catch (NotFoundException e) {
// aggregates two possible reasons of 404 error
// non existing problem or masterjudge
System.out.println("Non existing resource (problem, masterjudge), details available in the message: " + e.getMessage());
} catch (BadRequestException e) {
// aggregates two possible reasons of 400 error
// empty problem code, empty problem name
System.out.println("Bad request (empty problem code, empty problem name), details available in the message: " + e.getMessage());
} catch (ClientException e) {
System.out.println(e.getMessage());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
}
}
<?php
/**
* Example presents error handling for updateProblem() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once('../../../../vendor/autoload.php');
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'NONEXISTING_CODE';
$newProblemName = 'New example problem name';
try {
$response = $client->updateProblem($problemCode, $newProblemName);
} catch (SphereEngineResponseException $e) {
if ($e->getCode() == 401) {
echo 'Invalid access token';
} elseif ($e->getCode() == 403) {
echo 'Access to the problem is forbidden';
} elseif ($e->getCode() == 400) {
// aggregates two possible reasons of 400 error
// empty problem code, empty problem name
echo 'Bad request (empty problem code, empty problem name), details available in the message: ' . $e->getMessage();
} elseif ($e->getCode() == 404) {
// aggregates two possible reasons of 404 error
// non existing problem or masterjudge
echo 'Non existing resource (problem, masterjudge), details available in the message: ' . $e->getMessage();
}
}
"""
Example presents error handling for problems.update() API method
"""
from sphere_engine import ProblemsClientV3
from sphere_engine.exceptions import SphereEngineException
# define access parameters
accessToken = '<access_token>'
endpoint = '<endpoint>'
# initialization
client = ProblemsClientV3(accessToken, endpoint)
# API usage
problemCode = 'NONEXISTING_CODE'
newProblemName = 'New example problem name'
try:
response = client.problems.update(problemCode, newProblemName)
except SphereEngineException as e:
if e.code == 401:
print('Invalid access token')
elif e.code == 403:
print('Access to the problem is forbidden')
elif e.code == 400:
# aggregates two possible reasons of 400 error
# empty problem code, empty problem name
print('Bad request (empty problem code, empty problem name), details available in the message: ' + str(e))
elif e.code == 404:
# aggregates two possible reasons of 404 error
# non existing problem or masterjudge
print('Non existing resource (problem, masterjudge), details available in the message: ' + str(e))
var request = require('request');
// define access parameters
var accessToken = '<access_token>';
var endpoint = '<endpoint>';
// define request parameters
var problemCode = 'EXAMPLE';
var problemData = {
name: 'New name'
};
// send request
request({
url: 'https://' + endpoint + '/api/v3/problems/' + problemCode + '?access_token=' + accessToken,
method: 'PUT',
form: problemData
}, function (error, response, body) {
if (error) {
console.log('Connection problem');
}
// process response
if (response) {
if (response.statusCode === 200) {
console.log('Problem updated');
} else {
if (response.statusCode === 401) {
console.log('Invalid access token');
}
if (response.statusCode === 400) {
console.log('Empty code or empty name');
}
if (response.statusCode === 403) {
console.log('Access denied');
}
if (response.statusCode === 404) {
console.log('Problem or masterjudge does not exist');
}
}
}
});
Response example
{}
GET
/problems/:code/testcases?access_token=<access_token>
package problems.problems;
/**
* Example presents usage of the successful createProblemTestcase() API method
*/
import com.SphereEngine.Api.ProblemsClientV3;
import com.SphereEngine.Api.Exception.NotAuthorizedException;
import com.SphereEngine.Api.Exception.NotFoundException;
import com.SphereEngine.Api.Exception.ForbiddenException;
import com.SphereEngine.Api.Exception.ClientException;
import com.SphereEngine.Api.Exception.ConnectionException;
import com.google.gson.JsonObject;
public class createProblemTestcase
{
public static void main(String[] args)
{
ProblemsClientV3 client = new ProblemsClientV3(
"<access_token>",
"<endpoint>");
String code = "EXAMPLE";
String input = "model input";
String output = "model output";
Double timelimit = 5.0;
Integer judgeId = 1;
try {
JsonObject response = client.createProblemTestcase(code, input, output, timelimit, judgeId);
// response.get("number") stores the number of created testcase
} catch (NotAuthorizedException e) {
System.out.println("Invalid access token");
} catch (ForbiddenException e) {
System.out.println("Access to the problem is forbidden");
} catch (NotFoundException e) {
// aggregates two possible reasons of 400 error
// non existing problem and judge
System.out.println("Non existing resource (problem or judge), details available in the message: " + e.getMessage());
} catch (ClientException e) {
System.out.println(e.getMessage());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
}
}
<?php
/**
* Example presents error handling for createProblemTestcase() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once('../../../../vendor/autoload.php');
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$code = "EXAMPLE";
$input = "model input";
$output = "model output";
$timelimit = 5;
$nonexistingJudge = 9999;
try {
$response = $client->createProblemTestcase($code, $input, $output, $timelimit, $nonexistingJudge);
// response['number'] stores the number of created testcase
} catch (SphereEngineResponseException $e) {
if ($e->getCode() == 401) {
echo 'Invalid access token';
} elseif ($e->getCode() == 403) {
echo 'Access to the problem is forbidden';
} elseif ($e->getCode() == 404) {
// aggregates two possible reasons of 400 error
// non existing problem and judge
echo 'Non existing resource (problem or judge), details available in the message: ' . $e->getMessage();
}
}
"""
Example presents error handling for createProblemTestcase() API method
"""
from sphere_engine import ProblemsClientV3
from sphere_engine.exceptions import SphereEngineException
# define access parameters
accessToken = '<access_token>'
endpoint = '<endpoint>'
# initialization
client = ProblemsClientV3(accessToken, endpoint)
# API usage
code = 'EXAMPLE'
input = 'model input'
output = 'model output'
timelimit = 5
nonexistingJudge = 9999
try:
response = client.problems.createTestcase(code, input, output, timelimit, nonexistingJudge)
# response['number'] stores the number of created testcase
except SphereEngineException as e:
if e.code == 401:
print('Invalid access token')
elif e.code == 403:
print('Access to the problem is forbidden')
elif e.code == 404:
# aggregates two possible reasons of 400 error
# non existing problem and judge
print('Non existing resource (problem or judge), details available in the message: ' + str(e))
var request = require('request');
// define access parameters
var accessToken = '<access_token>';
var endpoint = '<endpoint>';
// define request parameters
var problemCode = 'EXAMPLE';
var testcaseData = {
input: 'Input',
output: 'Output',
timelimit: 5,
judgeId: 1
};
// send request
request({
url: 'https://' + endpoint + '/api/v3/problems/' + problemCode + '/testcases?access_token=' + accessToken,
method: 'POST',
form: testcaseData
}, function (error, response, body) {
if (error) {
console.log('Connection problem');
}
// process response
if (response) {
if (response.statusCode === 201) {
console.log(JSON.parse(response.body)); // testcase data in JSON
}
else {
if (response.statusCode === 401) {
console.log('Invalid access token');
}
if (response.statusCode === 400) {
console.log('Maximum number of test cases reached or timelimit is invalid');
}
if (response.statusCode === 403) {
console.log('Access denied');
}
if (response.statusCode === 404) {
console.log('Problem or judge does not exist');
}
if (response.statusCode === 409) {
console.log('Many test cases added at the same time ');
}
}
}
});
Response example
{
"number": 3
}
GET
/problems/:code/testcases/:number?access_token=<access_token>
curl -X GET 'https://<endpoint>/api/v3/problems/:code/testcases/:number?access_token=<access_token>'
package problems.problems;
/**
* Example presents usage of the successful getProblemTestcase() API method
*/
import com.SphereEngine.Api.ProblemsClientV3;
import com.SphereEngine.Api.Exception.NotAuthorizedException;
import com.SphereEngine.Api.Exception.NotFoundException;
import com.SphereEngine.Api.Exception.ForbiddenException;
import com.SphereEngine.Api.Exception.ClientException;
import com.SphereEngine.Api.Exception.ConnectionException;
import com.google.gson.JsonObject;
public class getProblemTestcase
{
public static void main(String[] args)
{
ProblemsClientV3 client = new ProblemsClientV3(
"<access_token>",
"<endpoint>");
String problemCode = "TEST";
Integer testcaseNumber = 0;
try {
JsonObject response = client.getProblemTestcase(problemCode, testcaseNumber);
} catch (NotAuthorizedException e) {
System.out.println("Invalid access token");
} catch (ForbiddenException e) {
System.out.println("Access to the problem is forbidden");
} catch (NotFoundException e) {
// aggregates two possible reasons of 404 error
// non existing problem or testcase
System.out.println("Non existing resource (problem, testcase), details available in the message: " + e.getMessage());
} catch (ClientException e) {
System.out.println(e.getMessage());
} catch (ConnectionException e) {
System.out.println(e.getMessage());
}
}
}
<?php
/**
* Example presents error handling for getProblemTestcase() API method
*/
use SphereEngine\Api\ProblemsClientV3;
use SphereEngine\Api\SphereEngineResponseException;
// require library
require_once('../../../../vendor/autoload.php');
// define access parameters
$accessToken = '<access_token>';
$endpoint = '<endpoint>';
// initialization
$client = new ProblemsClientV3($accessToken, $endpoint);
// API usage
$problemCode = 'TEST';
$nonexistingTestcaseNumber = 999;
try {
$response = $client->getProblemTestcase($problemCode, $nonexistingTestcaseNumber);
} catch (SphereEngineResponseException $e) {
if ($e->getCode() == 401) {
echo 'Invalid access token';
} elseif ($e->getCode() == 403) {
echo 'Access to the problem is forbidden';
} elseif ($e->getCode() == 404) {
// aggregates two possible reasons of 404 error
// non existing problem or testcase
echo 'Non existing resource (problem, testcase), details available in the message: ' . $e->getMessage();
}
}
"""
Example presents error handling for problems.getTestcase() API method
"""
from sphere_engine import ProblemsClientV3
from sphere_engine.exceptions import SphereEngineException
# define access parameters
accessToken = '<access_token>'
endpoint = '<endpoint>'
# initialization
client = ProblemsClientV3(accessToken, endpoint)
# API usage
problemCode = 'TEST'
nonexistingTestcaseNumber = 999
try:
response = client.problems.getTestcase(problemCode, nonexistingTestcaseNumber)
except SphereEngineException as e:
if e.code == 401:
print('Invalid access token')
elif e.code == 403:
print('Access to the problem is forbidden')
elif e.code == 404:
# aggregates two possible reasons of 404 error
# non existing problem or testcase
print('Non existing resource (problem, testcase), details available in the message: ' + str(e))
var request = require('request');
// define access parameters
var accessToken = '<access_token>';
var endpoint = '<endpoint>';
// define request parameters
var problemCode = 'EXAMPLE';
var testcaseNumber = 0;
// send request
request({
url: 'https://' + endpoint + '/api/v3/problems/' + problemCode + '/testcases/' + testcaseNumber + '?access_token=' + accessToken,
method: 'GET'
}, function (error, response, body) {
if (error) {
console.log('Connection problem');
}
// process response
if (response) {
if (response.statusCode === 200) {
console.log(JSON.parse(response.body)); // testcase data in JSON
}
else {
if (response.statusCode === 401) {
console.log('Invalid access token');
}
if (response.statusCode === 403) {
console.log('Access denied');
}
if (response.statusCode === 404) {
console.log('Testcase or problem not found');
}
}
}
});