import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
const FIGMA_TOKEN = process.env.FIGMA_TOKEN;
// Try with X-Figma-Token header instead of Bearer
const figmaApi = axios.create({
baseURL: "https://api.figma.com/v1/",
headers: { "X-Figma-Token": FIGMA_TOKEN },
});
async function testToken() {
console.log(`Testing token: ${FIGMA_TOKEN?.substring(0, 15)}...`);
// Test 1: Check if token is valid by getting user info
try {
console.log("\n1. Testing token validity (GET /v1/me)...");
const meResponse = await figmaApi.get("me");
console.log("✅ Token is valid!");
console.log("User:", meResponse.data.email);
} catch (error: any) {
console.log("❌ Token validation failed:", error.response?.data || error.message);
return;
}
// Test 2: Try to access the file
const fileKey = "YwUqmarhRx74Gb4zePtEUx";
try {
console.log(`\n2. Testing file access (GET /v1/files/${fileKey})...`);
const fileResponse = await figmaApi.get(`files/${fileKey}`);
console.log("✅ File is accessible!");
console.log("File name:", fileResponse.data.name);
console.log("Last modified:", fileResponse.data.lastModified);
} catch (error: any) {
console.log("❌ File access failed:", error.response?.data || error.message);
console.log("\nThis means either:");
console.log("- You don't have access to this file");
console.log("- The file is private");
console.log("- The file key is incorrect");
return;
}
// Test 3: Try to access the specific node
const nodeId = "8384:4";
try {
console.log(`\n3. Testing node access (GET /v1/files/${fileKey}/nodes?ids=${nodeId})...`);
const nodeResponse = await figmaApi.get(`files/${fileKey}/nodes`, {
params: { ids: nodeId },
});
console.log("✅ Node is accessible!");
console.log("Node data:", JSON.stringify(nodeResponse.data, null, 2).substring(0, 500) + "...");
} catch (error: any) {
console.log("❌ Node access failed:", error.response?.data || error.message);
}
}
testToken();