Exploring Codeforces API + Understanding API Signature (Day-14)
Diving into Codeforces API – Auth, Structure, and Signatures
Today I focused on understanding how the Codeforces API works — especially the authentication process and how to securely make calls using axios
.
The journey started with reading through the official Codeforces API documentation, and it opened up a whole new layer of how APIs work when authentication and data signing are involved.
What I Explored Today:
🔹 Intro to the Codeforces API:
-
The API is public and supports a wide range of data endpoints (user info, contest details, submissions, standings, etc.)
-
Responses are returned in JSON format
-
You can use the API freely, but certain endpoints require authentication via an API key + secret key.
Understanding the Method Structure:
-
Methods follow this format:
https://codeforces.com/api/{methodName}
Example:-
user.info
→ Fetch user details -
contest.standings
→ Fetch standings for a contest -
problemset.problems
→ Get the full problem set
-
-
Responses include:
-
status
: "OK" or "FAILED" -
result
: The actual object/data returned
-
Authentication Flow – The Tough Part
Some API methods require authenticated requests using:
-
apiKey
-
time
(current UNIX timestamp) -
apiSig
: An encrypted signature generated using SHA512 hashing
Challenge Faced – The apiSig
Puzzle
At first, the API signature format really confused me:
This format is strict. If even one param is out of order or missing, the API throws an error. What made it harder was:
-
Making sure all params are sorted lexicographically
-
Including the timestamp (
time
) correctly -
Hashing everything with SHA512
-
Making sure to not URL-encode by mistake before hashing
But after revisiting the documentation 3-4 times and looking at some real examples, I was finally able to understand how the pieces fit together.
Gracias:
Reading the official docs gave me clarity that no video tutorial ever could.
Grateful for the opportunity to learn how secure API communication really works. This will definitely help me when working with other APIs in the future.
~ Sanya
Comments
Post a Comment