163 lines
6.3 KiB
JavaScript
163 lines
6.3 KiB
JavaScript
import axios from "axios";
|
||
import dotenv from "dotenv";
|
||
|
||
dotenv.config();
|
||
|
||
const STEAM_APIS_KEY = process.env.STEAM_APIS_KEY || process.env.STEAM_API_KEY;
|
||
const BASE_URL = "https://api.steamapis.com";
|
||
|
||
console.log("\n╔═══════════════════════════════════════════════╗");
|
||
console.log("║ Steam API Test & Debug Script ║");
|
||
console.log("╚═══════════════════════════════════════════════╝\n");
|
||
|
||
console.log(`🔑 API Key: ${STEAM_APIS_KEY ? "✓ Configured" : "✗ Missing"}`);
|
||
if (STEAM_APIS_KEY) {
|
||
console.log(` First 10 chars: ${STEAM_APIS_KEY.substring(0, 10)}...`);
|
||
}
|
||
console.log();
|
||
|
||
if (!STEAM_APIS_KEY) {
|
||
console.error("❌ ERROR: No API key found!");
|
||
console.error("Set STEAM_APIS_KEY or STEAM_API_KEY in .env\n");
|
||
process.exit(1);
|
||
}
|
||
|
||
async function testAPI() {
|
||
try {
|
||
// Test CS2 (App ID 730)
|
||
console.log("─────────────────────────────────────────────────");
|
||
console.log("🎮 Testing CS2 Market Endpoint...\n");
|
||
|
||
const cs2Url = `${BASE_URL}/market/items/730`;
|
||
console.log(`📡 URL: ${cs2Url}`);
|
||
console.log(`🔑 Using API key: ${STEAM_APIS_KEY.substring(0, 10)}...\n`);
|
||
|
||
const cs2Response = await axios.get(cs2Url, {
|
||
params: {
|
||
api_key: STEAM_APIS_KEY,
|
||
},
|
||
timeout: 30000,
|
||
});
|
||
|
||
console.log("✅ Request successful!");
|
||
console.log(`📊 Status: ${cs2Response.status}`);
|
||
console.log(`📦 Response structure:`);
|
||
console.log(` - Has data property: ${cs2Response.data ? "✓" : "✗"}`);
|
||
console.log(` - Data type: ${typeof cs2Response.data}`);
|
||
|
||
if (cs2Response.data) {
|
||
console.log(` - Data keys: ${Object.keys(cs2Response.data).join(", ")}`);
|
||
|
||
if (cs2Response.data.data) {
|
||
const itemCount = Object.keys(cs2Response.data.data).length;
|
||
console.log(` - Items in data.data: ${itemCount}`);
|
||
|
||
if (itemCount > 0) {
|
||
const firstItems = Object.keys(cs2Response.data.data).slice(0, 5);
|
||
console.log("\n📋 Sample items:");
|
||
firstItems.forEach((itemName) => {
|
||
const item = cs2Response.data.data[itemName];
|
||
console.log(`\n "${itemName}":`);
|
||
console.log(` - Type: ${typeof item}`);
|
||
if (item && typeof item === "object") {
|
||
console.log(` - Keys: ${Object.keys(item).join(", ")}`);
|
||
if (item.prices) {
|
||
console.log(` - Has prices: ✓`);
|
||
console.log(` - Price types: ${Object.keys(item.prices).join(", ")}`);
|
||
if (item.prices["30"]) {
|
||
console.log(` - 30-day price: $${item.prices["30"]}`);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
} else {
|
||
console.log("\n ⚠️ No items found in response!");
|
||
}
|
||
} else {
|
||
console.log(" - No 'data' property in response.data");
|
||
console.log("\n Full response preview:");
|
||
console.log(JSON.stringify(cs2Response.data, null, 2).substring(0, 500));
|
||
}
|
||
}
|
||
|
||
console.log("\n─────────────────────────────────────────────────");
|
||
console.log("🔧 Testing Rust Market Endpoint...\n");
|
||
|
||
const rustUrl = `${BASE_URL}/market/items/252490`;
|
||
console.log(`📡 URL: ${rustUrl}\n`);
|
||
|
||
const rustResponse = await axios.get(rustUrl, {
|
||
params: {
|
||
api_key: STEAM_APIS_KEY,
|
||
},
|
||
timeout: 30000,
|
||
});
|
||
|
||
console.log("✅ Request successful!");
|
||
console.log(`📊 Status: ${rustResponse.status}`);
|
||
console.log(`📦 Response structure:`);
|
||
console.log(` - Has data property: ${rustResponse.data ? "✓" : "✗"}`);
|
||
|
||
if (rustResponse.data && rustResponse.data.data) {
|
||
const itemCount = Object.keys(rustResponse.data.data).length;
|
||
console.log(` - Items in data.data: ${itemCount}`);
|
||
|
||
if (itemCount > 0) {
|
||
const firstItems = Object.keys(rustResponse.data.data).slice(0, 3);
|
||
console.log("\n📋 Sample items:");
|
||
firstItems.forEach((itemName) => {
|
||
const item = rustResponse.data.data[itemName];
|
||
console.log(`\n "${itemName}"`);
|
||
if (item && item.prices && item.prices["30"]) {
|
||
console.log(` - 30-day price: $${item.prices["30"]}`);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
console.log("\n─────────────────────────────────────────────────");
|
||
console.log("\n✅ API Test Complete!\n");
|
||
|
||
} catch (error) {
|
||
console.error("\n❌ ERROR during API test:");
|
||
console.error(` Message: ${error.message}\n`);
|
||
|
||
if (error.response) {
|
||
console.error("📡 Response details:");
|
||
console.error(` Status: ${error.response.status}`);
|
||
console.error(` Status Text: ${error.response.statusText}`);
|
||
|
||
if (error.response.status === 401) {
|
||
console.error("\n🔑 Authentication Error:");
|
||
console.error(" Your API key is invalid or expired.");
|
||
console.error(" Get a new key from: https://steamapis.com/");
|
||
} else if (error.response.status === 429) {
|
||
console.error("\n⏱️ Rate Limit Error:");
|
||
console.error(" You've exceeded the API rate limit.");
|
||
console.error(" Wait a few minutes and try again.");
|
||
} else if (error.response.status === 403) {
|
||
console.error("\n🚫 Forbidden:");
|
||
console.error(" Your API key doesn't have access to this endpoint.");
|
||
console.error(" Check your subscription plan at https://steamapis.com/");
|
||
}
|
||
|
||
if (error.response.data) {
|
||
console.error("\n📦 Response data:");
|
||
console.error(JSON.stringify(error.response.data, null, 2));
|
||
}
|
||
} else if (error.request) {
|
||
console.error("\n🔌 Network Error:");
|
||
console.error(" No response received from server.");
|
||
console.error(" Check your internet connection.");
|
||
}
|
||
|
||
console.error("\n📚 Stack trace:");
|
||
console.error(error.stack);
|
||
console.error();
|
||
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
testAPI();
|