S
Supabase4w ago
Tim

jwt malformed with OAuth2 for analytics/endpoints/logs.all

Seeing {"message":"jwt malformed"} for requests to analytics/endpoints/logs.all using an OAuth2 token. I am using the same token for creating edge functions and more via the MCP. Is this endpoint not available for OAuth tokens? If so, what should I do if I want more than the latest logs for the past 1 minute?
6 Replies
Tim
TimOP4w ago
Is the issue that I try to send SQL for getting logs from a specific edge function? Read something that said similar to that we cannot execute SQL with the OAuth2 token here: https://discord.com/channels/839993398554656828/1357000137922183240/1357000137922183240 Update. Tried without any custom SQL, still does not work
ihm40
ihm404w ago
const sqlQuery = `
SELECT
id,
function_edge_logs.timestamp,
event_message,
response.status_code,
request.method,
m.function_id,
m.execution_time_ms,
m.deployment_id,
m.version
FROM function_edge_logs
CROSS JOIN UNNEST(metadata) as m
CROSS JOIN UNNEST(m.response) as response
CROSS JOIN UNNEST(m.request) as request
ORDER BY timestamp DESC
LIMIT 25
`.trim();

// Build URL with query parameters
const params = new URLSearchParams({
sql: sqlQuery,
iso_timestamp_start,
iso_timestamp_end
});

const url = `${SUPABASE_API_BASE_URL}/v1/projects/${projectId}/analytics/endpoints/logs.all?${params.toString()}`;

const logsResponse = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});
const sqlQuery = `
SELECT
id,
function_edge_logs.timestamp,
event_message,
response.status_code,
request.method,
m.function_id,
m.execution_time_ms,
m.deployment_id,
m.version
FROM function_edge_logs
CROSS JOIN UNNEST(metadata) as m
CROSS JOIN UNNEST(m.response) as response
CROSS JOIN UNNEST(m.request) as request
ORDER BY timestamp DESC
LIMIT 25
`.trim();

// Build URL with query parameters
const params = new URLSearchParams({
sql: sqlQuery,
iso_timestamp_start,
iso_timestamp_end
});

const url = `${SUPABASE_API_BASE_URL}/v1/projects/${projectId}/analytics/endpoints/logs.all?${params.toString()}`;

const logsResponse = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});
This has worked for me before but i was using access/refresh tokens and i think the thing you were using it is the a PAT token (which probably should still work) What is it you are trying to do?
Tim
TimOP3w ago
I am using access/refresh tokens and writing flow for agents to write supabase projects
ihm40
ihm403w ago
does the above code i provided work for you using access token (note it is biqeuery sql)
Tim
TimOP3w ago
I think the issue was literally calling the endpoint using access tokens and providing a SQL query but will check again
ihm40
ihm403w ago
yeah let me know, this has definitely worked for me in the past unless something has changed recently

Did you find this page helpful?