Skip to content

Quick Start Guide

This guide will help you quickly get started with the CSMarketCap API.

Step 1: Get Your API Key

  1. Log in to your account at CSMarketCap
  2. Navigate to the "API Keys" section
  3. Generate a new API Key if you don't already have one
  4. Save your API Key securely - you'll need it for the next step

Step 2: Generate a JWT Token

Use your API Key to generate a JWT token:

js
const axios = require('axios');

async function generateJWTToken(apiKey) {
  const mutation = `
    mutation {
      createSubscriptionToken(api_key: "${apiKey}")
    }
  `;

  try {
    const response = await axios({
      url: 'https://api.csmarketcap.com/api/v2/graphql',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: {
        query: mutation
      }
    });

    const jwtToken = response.data.data.createSubscriptionToken;
    console.log('Your JWT Token:', jwtToken);
    return jwtToken;
  } catch (error) {
    console.error('Error generating JWT token:', error);
  }
}

// Replace with your actual API key
generateJWTToken('your_api_key_here');

This token will be valid for 30 days. Store it securely.

Step 3: Make Your First API Request

Now you can make API requests using your JWT token. Here's an example requesting price recommendations:

js
const axios = require('axios');

async function getPriceRecommendations(gameId = 730, type = 'general') {
  const query = `
    query PriceRecommendations($game_id: Int, $type: RecommendationType) {
      getPriceRecommendations(game_id: $game_id, type: $type) {
        market_hash_name
        suggested_price
        unstable_reasons
        total_sales
        price_difference
        price_change_percentage
      }
    }
  `;

  try {
    const response = await axios({
      url: 'https://api.csmarketcap.com/api/v2/graphql',
      method: 'post',
      headers: {
        'Content-Type': 'application/json',
        'api-token': 'YOUR_JWT_TOKEN_HERE'
      },
      data: {
        query: query,
        variables: {
          game_id: gameId,
          type: type
        }
      }
    });

    console.log('Price recommendations:', response.data.data.getPriceRecommendations);
    return response.data.data.getPriceRecommendations;
  } catch (error) {
    console.error('Error fetching price recommendations:', error);
  }
}

getPriceRecommendations();

Step 4: Explore Other Endpoints

The CSMarketCap API offers several endpoints to meet different needs:

  1. Price Recommendations - Get suggested prices for items
  2. Market Analytics - View detailed market data for specific marketplaces
  3. Steam Analytics - Access Steam-specific market data
  4. Min Prices - Compare lowest prices across marketplaces
  5. Max Orders - Find highest buy orders across marketplaces

Step 5: Implement Error Handling

Always implement proper error handling in your production code:

js
try {
  // API request code
} catch (error) {
  if (error.response) {
    // The request was made and the server responded with an error status
    console.error('Server error:', error.response.data);
    console.error('Status code:', error.response.status);
    
    // Handle specific error cases
    if (error.response.status === 401) {
      console.error('Authentication error. JWT token may be expired or invalid.');
      // Logic to refresh the token
    }
  } else if (error.request) {
    // The request was made but no response was received
    console.error('Network error. No response received:', error.request);
  } else {
    // Something happened in setting up the request
    console.error('Request setup error:', error.message);
  }
}

Step 6: Consider Rate Limits

Reference to plan limits: https://csmarketcap.com/pricing

Next Steps

  • Read the Introduction for detailed information
  • Review the Authentication Guide for more details on token management
  • Explore the sample code to understand how to integrate the API into your applications

For any questions or support, contact our support team via Telegram.

Need help? Contact our support team