Fefer_Ivan's blog

By Fefer_Ivan, 10 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, a user must create an API-key at /settings/api and read the bottom part of the manual at /apiHelp.

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

We are open to 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

| Write comment?
»
10 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)

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

Good work!

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

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

»
10 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.

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

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

»
10 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

»
10 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.

  • »
    »
    10 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. :)

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

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

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

Amazing!

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

The best update ever! Thanks!

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

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

»
10 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 :)

»
10 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.

  • »
    »
    10 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

    • »
      »
      »
      10 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.

      • »
        »
        »
        »
        10 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.

        • »
          »
          »
          »
          »
          10 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?

          • »
            »
            »
            »
            »
            »
            10 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

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

IN THIS CONTEST WILL BE RATED OR NOT?

»
10 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.

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

    It will be implemented. Thanks.

    • »
      »
      »
      10 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.

»
10 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')

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

    Interesting! While writing this comment, did you know you'll be red on day?

»
10 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?

  • »
    »
    10 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.

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

Congratulations,better and better everyday in everyway

»
10 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.

»
10 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.

»
10 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.

  • »
    »
    10 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.
    • »
      »
      »
      10 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 :-)

»
10 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!

»
10 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?

  • »
    »
    10 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.

»
10 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?

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    • »
      »
      »
      10 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 :(

»
10 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.

»
10 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.

»
9 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?

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

Is this a bug?

Request: http://mirror.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://mirror.codeforces.com/api/user.ratedList

Also, in request: http://mirror.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".

»
9 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 ?

  • »
    »
    9 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...

»
8 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.

»
8 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.

»
7 years 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

»
6 years 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.

»
6 years 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://mirror.codeforces.com/api/problemset.problems gives a lot more count than the correct count. Maybe it is giving total number of accepted solution?

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

/api/help isn't working now.

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

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

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

I'm trying to get some data from the API, but I encountered some errors and I would like to ask one question. When I try to get user.info with a username that doesn't actually exist, the response headers doesn't includes Access-Control-Allow-Origin, so I cannot get any information through Fetch API or XMLHttpRequest API etc., even whether fail or not. In addition, It is an error on browser and cannot be handled in web application. How can I handle this? Is there a way to check if a username exists by other Codeforces API method? (Of course, scraping can be one of the way to implement this, but I need easier way.)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it -39 Vote: I do not like it

    Hello, thanks. Added Access-Control-Allow-Origin: * for all responses from API.

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

      Hey Mike, I reached out to you about this exact issue over DM ~2 months ago, but the message went unread. A few months ago mblazev attempted to report an issue with a blog, which was maybe not noticed.
      While I understand that you cannot read every DM or blog, it would be good to have a reliable method of reporting issues regarding the Codeforces API or website, ideally something like an issues page on Github.

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

      Bump on this.

      For instance, here's a minor bug
»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Hi Did the "submit a solution" feature (as you mentioned) added ? I looked but I couldn't see. I wonder if is it get overlooked There is no any write-methods if I didn't see it wrong Don't you think of adding it ? or did you give up ? I think it would be very useful

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

How to get the list upcoming contest using this API?

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

Is there any API to get favourites tab problems && contests of a user?

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

The API isn't working for one submission from one user.

https://mirror.codeforces.com/api/user.status?handle=jeroenodb&from=1&count=100 Works

https://mirror.codeforces.com/api/user.status?handle=jeroenodb&from=1&count=500 Error

https://mirror.codeforces.com/api/user.status?handle=jeroenodb&from=306&count=1 Error, in fact, this is the offending item!

(Note: this number might change if jeroenodb submits more.)

Weirdly, it looks like you can see the submission (117415184) on their submissions page, so maybe this only affects API?

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

Is there a way to query only accepted submissions from a specific user ?

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

    You can check if the verdict equals "OK" for each object in the result array.

    JS Code (Client)
    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes I'm also aware of this. But it would be hard if I try to query accounts that made too many submissions.

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

        Yes, you are right. But there does not seem to be a way to query only accepted submissions from a specific user.

        Maybe requesting MikeMirzayanov add an extra optional parameter like acceptedOnly or verdict to user.status method might help.

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

8 years later, we still don't have a write method. can someone please update about the progress in the same.

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

is there a way to get code of submission through API