Due to technical reasons Codeforces may be unavailable on April 21st from 01:00-07:00 (MSK). ×

Fefer_Ivan's blog

By Fefer_Ivan, 5 years ago, translation, In English,

Hello, Codeforces!

Today we want to introduce Codeforces API. With it you now can access some of Codeforces data in machine-readable JSON format.

API has a detailed manual, which is supported to contain only actual information. Every method has an example URL. You can use it to see the example response and to experiment with different parameters.

By default, any API request will be anonymous and will have access only to public data. To make a request on behalf of some user, user must create an API-key at /settings/api and read the bottom part of manual at /api/help.

For now, all methods are read-only. Write-methods like "submit a solution" are comming soon.

We are open for suggestions and requests for new API-methods. Especially from respected members of contest programming community.

With best regards, Ivan.

 
 
 
 
  • Vote: I like it  
  • +429
  • Vote: I do not like it  

»
5 years ago, # |
  Vote: I like it +22 Vote: I do not like it

Very nice work, good luck in future and adding write-method as quick as possible)

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Good work!

»
5 years ago, # |
  Vote: I like it +20 Vote: I do not like it

What can I do with these? I can't understand enough.

»
5 years ago, # |
Rev. 2   Vote: I like it +12 Vote: I do not like it

Maybe it will be good to include the 3-byte color code (or css class) of the rating in User object for the people who will make their own Codeforces widget.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The link "settings/api" should be "/settings/api".

»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Oh wow, once the write methods are in, we could create a command line problem-read and submit tool (Parsers already available could be extended) for command line lovers. The whole round would run through the command line! But I'll still love the Codeforces site because its really well designed :D

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Great news! I'd like to be able to get list of test cases for problems via the API.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    if that's possible, then i think we will be able to see big testcases in full (instead of only first ~100 characters).
    if this happens, it would be really awesome. :)

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Oh, I actually meant the sample test cases from problem statement!

»
5 years ago, # |
  Vote: I like it +18 Vote: I do not like it

Amazing!

»
5 years ago, # |
  Vote: I like it +30 Vote: I do not like it

The best update ever! Thanks!

»
5 years ago, # |
  Vote: I like it +2 Vote: I do not like it

just when I think it can't get any better :D

»
5 years ago, # |
  Vote: I like it +9 Vote: I do not like it

I think I will write a plugin for vim later so that I can read problem statements, do coding and submit the solutions in vim and throw away the web browser :)

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

if they provide api for viewing problems(past or current contest) and submitting problem solution, then someone(me) can build topcoder arena type software. But its nice work.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +54 Vote: I do not like it

    Considering the amount of hate TC arena gets, I'd say that it's better to leave things in webpage format :D

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 3   Vote: I like it 0 Vote: I do not like it

      yep, webpage format is good, but I'd like to have something that allows me to run my program with sample test cases without using the typical CTRL+C and CTRL+V, and send my file without looking for it and something like that.

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It's hardly different from 2-3 clicks. But I usually copy all samples into the command line using <<< "", because I can switch between testing them and compiling at the speed of repeatedly pressing up-arrow (read: extremely fast). If I click too fast in TC arena, it says that the server's busy; if I do it in the command line, the commands (for example, compile run sample 1 run sample 2, which are (up up up enter)x3) are queued, so it actually has more benefits if one prefers keyboard to mouse.

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I respect it, it's a matter of opinion, but I was thinking on a tool that copy I/O and let you know if they match or not, like greed, without as you said waiting the response of TC arena, and also let you customize more things. Well one question, how would you like to use the new API?

          • »
            »
            »
            »
            »
            »
            5 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Yeah, to everyone their own. I don't really have a use for it, my programming tools are a (preferrably Linux-styled) console, a text editor with syntax highlighting and my own self :D

»
5 years ago, # |
Rev. 2   Vote: I like it -77 Vote: I do not like it

IN THIS CONTEST WILL BE RATED OR NOT?

»
5 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Is jsonp callback supported by the api? I'm trying to do ajax through jquery. If my request datatype is set to "json", then due to cross-origin policy it's not possible to send the request. If I set it to "jsonp", the server returns "json", thus the client library can't parse the returned data since it's expecting a "jsonp". I can see on the Network tab of chrome that json-data is already returned by the server but ajax library of jquery can't parse it due to datatype mismatch. Can anyone provide a solution/workaround to this problem? I don't want to use an intermediate server side to get the data at client side, though that way I can easily get it but in my opinion that is just a bypass solution.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    It will be implemented. Thanks.

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it -8 Vote: I do not like it

      It has been 10 months, and I still see this same issue.

      Maybe just use the simple solution and add: Access-Control-Allow-Origin to your API response? I don't see any security concern here, since what we can do with CF API is quite limited to getting info that is already available.

»
5 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Yeay more API => more scripts. :) Can't wait to see amazing Codeforces scripts :)

(what I really want : filter Contest Standing by 'Country')

»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

i was created sha512 hash in python :

hashlib.sha512(data).hexdigest()

making request gives incorrect signature. is there any problem in sha function or something else?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The function is correct.

    It looks like you have some errors in building the string to hash.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Congratulations,better and better everyday in everyway

»
5 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I think a method to return all problems here would be great (with this page's links and information, not the contest's information). Can you add this please? I need it to convert all my code to use the API.

I know I can get the list of contests, and for each contest get its problems, but this will not work for me.

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

I'm afraid someone may create bots to hack others. This could do damage to the fairness.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Methods like "submit a solution" are dangerous.
So spammers can write programs to download and submit other users answers for their own account. And go up in problemset standings.

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    i want to say two things:

    • i don't think anyone would want to solve problems in practice just to go up in Problemset Standings. i would rather solve problems in contest (and get the bonus of increasing my Rating), when solutions will not be publicly available.
    • if there are users really desperate to solve problems in practice, they can just copy-paste solutions of other users and submit them from their own accounts by the usual method. i agree they can do it faster using the API, but i don't think this is a major concern right now.
    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +11 Vote: I do not like it

      Also for such people coding a bot might give more experience (hence deeper knowledge) than the manual copy-pasting so it still serves a purpose of educating people :-)

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you for creating this. It was very good timing for me; I was just asked to make a script to track Codeforces activity for US IOI contestants, and the API was very helpful!

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I'm writing python scripts to pull data and planning to do some analysis. But I find it's hard to deal with the problems which appear in both div.1 and div.2 contests. I can't find a way to get the contest id of corresponding div.1 AND div.2 contest. I can only get one of them (div.1 OR div.2) from the problemset.problem api. Is there someone who can tells me which api should I use?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I also found that the "Solved" part of the website is a little confusing. For these problems which are in both div.1 and div.2 contest, when I add them to my favourite problems, and go to my fav. problem page, the "Solved" value is "the number of users who solved this problem in div.1" or that of div.2. In "ProblemSet" page, "Solved" is problem.solved; in "Contest"->"Problem" page, "Solved" is contest.problem.solved; in "Favourites" page, "Solved" is contest1.problem.solved or contest2.problem.solved.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I'm still waiting for submit method...
Wouldn't it be one of the most useful ones?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      This is not API. I want to know submission results (CF unavailable, submitted, duplicate, etc.). If there would be ab API method, doing this would be much easier. Your program is great, but it doen't show this, and I think parsing HTML to see submission details would be very hard :(

      So it should be extended, API's raw and unusable now :(

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there any way to get all DIV-1 contests ID ?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you please add the number of people solved a particular problem and the date when the problem published in the problemset.problem api. I want to make a recommendation system. Thank you. This api is great.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

user.info is returning 414 : Request URI too Long error, even when I have less than 5000 handles in my query. I think you need to remove that restriction from the server when the docs says 10000 handles.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Could you please expose a method for us to get the original source codes for our submissions?

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Is this a bug?

Request: http://codeforces.com/api/user.status?handle=Ad... Response: {"status":"FAILED","comment":"handle: Field should contain only Latin letters, digits, underscore or dash characters"}

But user "Ad..." exists in http://codeforces.com/api/user.ratedList

Also, in request: http://codeforces.com/api/user.status?handle=mR.ilchi the handle "mR.ilchi" contains "." which is not Latin letters, digits, underscore nor dash characters. But the response status is "OK".

»
3 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

"Write-methods like "submit a solution" are comming soon" when will it show up ?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Was checking out this also, found that it is still implementating for 19 months...

»
2 years ago, # |
  Vote: I like it +8 Vote: I do not like it

So, how are the write-methods comming up? I would really love to use them.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is there any way to get the list of upcoming contest. By using contest.list method it returns a total list of all contest in codeforces, which makes my website slower.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

What happened to write methods? We've been waiting for 4 years now lol

»
10 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Is there any problemId for problem? In problem Object problemId is absent. I need a way to uniquely identify problem. Combination of problem index and contestId might not work as sometimes same problem appear both in div1 and div2. Any kind of suggestion will be appreciated.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How can I get correct unique number of accepted solutions for a given problem? https://codeforces.com/api/problemset.problems gives a lot more count than the correct count. Maybe it is giving total number of accepted solution?

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

/api/help isn't working now.

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Try opening without login on codeforces. This is a known issue.