Appearance
Authentication Guide
JWT Token Authentication
The API requires JWT (JSON Web Token) authentication for all requests. This guide explains how to generate API Key and generate temporary JWT token using API Key.
Getting API Key
To get the API Key from CSMC:
- Log in to your profile at https://csmarketcap.com/profile
- Navigate to the "API Keys" section at https://csmarketcap.com/profile
- Click "Generate New API Key" or use the existing if it was priorly generated
- Copy your API Key.
Done ✅
Generating JWT Token
After obtaining your API Key, you can use it to generate a temporary JWT token by making a GraphQL mutation request:
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);
bash
curl -X POST https://api.csmarketcap.com/api/v2/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation { createSubscriptionToken(api_key: \"YOUR_API_KEY\") }"
}'
The response will contain your JWT token:
json
{
"data": {
"createSubscriptionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
This JWT token will be valid for 2 hours, after which you'll need to generate a new one.
Using Your JWT Token
Include your JWT token in the header of all API requests:
api-token: <your_jwt_token>
For example, when using curl:
bash
curl -X POST https://api.csmarketcap.com/api/v2/graphql \
-H "Content-Type: application/json" \
-H "api-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-d '{"query": "{ getPriceRecommendations(game_id: 730, type: general) { market_hash_name suggested_price } }"}'
Token Expiration
JWT tokens expire after 2 hours for security reasons. When a token expires, you'll need to generate a new one following the steps above.
Troubleshooting
If you receive authentication errors:
- Verify your token is valid and hasn't expired
- Check that you're including the token in the correct header format
- Ensure your profile has access to the requested resources
- If problems persist, generate a new token
For further assistance, contact our support team via Telegram.