Skip to main content
CodePlanet Docs

Api Guide

Get started with the CodePlanet API in under 10 minutes. This guide covers authentication, common use cases, and provides code snippets for popular languages.

What is an API Key?

An API Key is like a password for applications. It allows you to write scripts or build apps that interact with CodePlanet on your behalf.

User API keys start with cp_live_ followed by a secure random string.

How to Generate a Key

  1. Go to Settings → API Keys.
  2. Click Generate New Key.
  3. Give it a name (e.g., "My Python Script").
  4. Copy the key immediately. We only show it once!

Authentication

All API requests must include your API key in the Authorization header or x-api-key header.

Header Format:

Authorization: Bearer cp_live_xxxxxxxxxxxxxxxxxxxxxxxx

Quick Start Examples

Here is how to fetch your user profile in different languages.

JavaScript (Fetch)

const API_KEY = 'cp_live_...';
 
fetch('https://codeplanet.dev/api/v1/user/profile', {
  headers: {
    'Authorization': `Bearer ${API_KEY}`
  }
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error(err));

Node.js (Axios)

const axios = require('axios');
 
async function getProfile() {
  try {
    const response = await axios.get('https://codeplanet.dev/api/v1/user/profile', {
      headers: { 'Authorization': 'Bearer cp_live_...' }
    });
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}
 
getProfile();

Python (Requests)

import requests
 
api_key = "cp_live_..."
url = "https://codeplanet.dev/api/v1/user/profile"
 
headers = {
    "Authorization": f"Bearer {api_key}"
}
 
response = requests.get(url, headers=headers)
print(response.json())

Common Use Cases

1. Fetch Problems

Retrieve a list of coding problems.

GET /api/v1/problems?page=1&limit=10&difficulty=easy

Response:

{
  "success": true,
  "data": [
    { "id": "two-sum", "title": "Two Sum", "difficulty": "Easy" },
    ...
  ]
}

2. Get User Stats

See your XP, streaks, and solve counts.

GET /api/v1/user/stats

3. Bookmark a Problem

Save a problem for later.

POST /api/v1/problems/two-sum/bookmark

4. Read Activity Feed

Get recent activity from you and people you follow.

GET /api/v1/activity/feed

Rate Limiting

To prevent abuse, we limit the number of requests you can make.

PlanRequests / Day
Free100
Developer1,000
Pro10,000

We provide headers in every response to help you track usage:

  • X-RateLimit-Limit: Your total daily limit.
  • X-RateLimit-Remaining: Requests left today.
  • X-RateLimit-Reset: Timestamp when your limit refreshes.

If you hit the limit, you will receive a 429 Too Many Requests error. The Retry-After header tells you how many seconds to wait.


Error Handling

StatusMeaningSolution
401UnauthorizedCheck if your API Key is correct.
403ForbiddenYour plan does not allow this action.
404Not FoundThe resource (e.g., problem ID) doesn't exist.
429Rate LimitedYou've hit your daily limit. Upgrade or wait.
500Server ErrorSomething went wrong on our end. Try again later.

Need help? Join our Discord Community.

On this page