Repository navigation
Expand file tree
/
Copy pathdebug-search-api.js
More file actions
121 lines (102 loc) Β· 3.73 KB
/
Copy pathdebug-search-api.js
File metadata and controls
121 lines (102 loc) Β· 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import fetch from "node-fetch";
async function testSearchAPI() {
const apiKey = process.env.TALENT_API_KEY;
if (!apiKey) {
console.error("Missing TALENT_API_KEY environment variable");
return;
}
console.log("π Testing Talent Protocol Search API...\n");
// Same query as used in getCreatorScoreLeaderboard
const data = {
query: {
score: {
min: 1,
scorer: "Creator Score",
},
},
sort: {
score: { order: "desc", scorer: "Creator Score" },
id: { order: "desc" },
},
page: 1,
per_page: 50,
};
const queryString = [
`query=${encodeURIComponent(JSON.stringify(data.query))}`,
`sort=${encodeURIComponent(JSON.stringify(data.sort))}`,
`page=${data.page}`,
`per_page=${data.per_page}`,
`view=scores_minimal`,
].join("&");
const url = `https://api.talentprotocol.com/search/advanced/profiles?${queryString}`;
console.log("π‘ Making request to:", url);
console.log("π Using API key:", apiKey.substring(0, 8) + "...");
try {
const response = await fetch(url, {
headers: {
Accept: "application/json",
"X-API-KEY": apiKey,
},
});
console.log("\nπ Response Status:", response.status, response.statusText);
if (!response.ok) {
const errorText = await response.text();
console.error("β Error response:", errorText);
return;
}
const json = await response.json();
const profiles = json.profiles || [];
console.log(`\nπ Found ${profiles.length} profiles`);
console.log("π Looking for poet.base.eth...\n");
// Find poet.base.eth
const poetProfile = profiles.find(
(p) =>
p.display_name?.toLowerCase().includes("poet") ||
p.display_name?.toLowerCase().includes("poet.base.eth"),
);
if (poetProfile) {
const poetIndex = profiles.findIndex((p) => p.id === poetProfile.id);
console.log("β
FOUND poet.base.eth!");
console.log(`π Position in search results: ${poetIndex + 1}`);
console.log(`π€ Display name: "${poetProfile.display_name}"`);
console.log(`π ID: ${poetProfile.id}`);
console.log(`π Scores:`, poetProfile.scores);
// Extract Creator Score
const creatorScores = Array.isArray(poetProfile.scores)
? poetProfile.scores
.filter((s) => s.slug === "creator_score")
.map((s) => s.points ?? 0)
: [];
const score = creatorScores.length > 0 ? Math.max(...creatorScores) : 0;
console.log(`π― Creator Score: ${score}`);
console.log(`π Rank field: ${poetProfile.rank || "NOT SET"}`);
console.log(
`π Rank position field: ${poetProfile.rank_position || "NOT SET"}`,
);
console.log("\nπ Full profile data:");
console.log(JSON.stringify(poetProfile, null, 2));
} else {
console.log("β poet.base.eth NOT FOUND in search results");
console.log("\nπ First 10 profiles:");
profiles.slice(0, 10).forEach((p, i) => {
console.log(`[${i + 1}] ${p.display_name} - ID: ${p.id}`);
});
}
// Also check first 20 profiles to see rank patterns
console.log("\nπ First 20 profiles with their rank data:");
profiles.slice(0, 20).forEach((p, i) => {
const creatorScores = Array.isArray(p.scores)
? p.scores
.filter((s) => s.slug === "creator_score")
.map((s) => s.points ?? 0)
: [];
const score = creatorScores.length > 0 ? Math.max(...creatorScores) : 0;
console.log(
`[${i + 1}] ${p.display_name}: score=${score}, rank=${p.rank || "N/A"}, rank_position=${p.rank_position || "N/A"}`,
);
});
} catch (error) {
console.error("π₯ Error making API call:", error);
}
}
testSearchAPI();