From 46bcf2b5e837bfbc957db60a5c674742f3916083 Mon Sep 17 00:00:00 2001 From: wikiapiserver Date: Fri, 26 Jun 2026 01:32:11 +0200 Subject: fix: filter to English Wikipedia via POST with filter body The structured contents API requires a POST request with the filter in the JSON body to narrow results: {"filters": [{"field": "in_language.identifier", "value": "en"}]} Replaces the non-functional query-string filter parameter. --- api/handlers.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'api') diff --git a/api/handlers.go b/api/handlers.go index d3a08fd..4299b74 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -3,6 +3,7 @@ package api import ( "context" "io" + "bytes" "database/sql" "errors" "encoding/json" @@ -228,14 +229,25 @@ func (h *Handler) GetArticle(w http.ResponseWriter, r *http.Request) { } baseURL := "https://api.enterprise.wikimedia.com/v2/structured-contents/" + url.QueryEscape(article) - queryURL := baseURL + "?limit=1" - req, err := http.NewRequestWithContext(ctx, "GET", queryURL, nil) + body, err := json.Marshal(map[string]any{ + "filters": []map[string]string{ + {"field": "in_language.identifier", "value": "en"}, + }, + }) + if err != nil { + serverError(w, "could not build request") + return + } + + req, err := http.NewRequestWithContext(ctx, "POST", baseURL, bytes.NewReader(body)) if err != nil { serverError(w, "could not build request") return } req.Header.Set("Authorization", "Bearer "+acct.AccessToken) + req.Header.Set("Content-Type", "application/json") + queryURL := baseURL start := time.Now() resp, err := http.DefaultClient.Do(req) -- cgit v1.2.3