mickael-kerjean/filestash · error

API returned status %d: %s

Error message

API returned status %d: %s

What it means

Returned by Syncthing.makeAPICall when the Syncthing REST API (e.g. /rest/config) responds with a non-200 status. The message carries the status code and raw response body, covering auth failures (bad X-Api-Key → 403), wrong URL prefix, or Syncthing errors; callers fetchFolders and listDirectory then fail.

Source

Thrown at server/plugin/plg_backend_syncthing/index_helper.go:50

	}

	req, err := http.NewRequest("GET", apiURL, nil)
	if err != nil {
		return nil, err
	}
	req.Header.Set("X-Api-Key", s.apiKey)
	resp, err := s.client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("API returned status %d: %s", resp.StatusCode, string(body))
	}
	return body, nil
}

func (s *Syncthing) fetchFolders() ([]SyncFolder, error) {
	data, err := s.makeAPICall("/rest/config", nil)
	if err != nil {
		return nil, err
	}
	var config struct {
		Folders []struct {
			ID    string `json:"id"`
			Label string `json:"label"`
			Path  string `json:"path"`
		} `json:"folders"`
	}
	if err := json.Unmarshal(data, &config); err != nil {
		return nil, err

View on GitHub (pinned to 78f756eb94)

Solutions

  1. Verify the configured API key matches Syncthing's GUI/API key and that X-Api-Key is accepted (403 vs 404 distinction)
  2. Check the Syncthing URL/host/port, including any reverse-proxy path prefix
  3. Read the response body in the error — Syncthing includes the reason there
  4. Confirm Syncthing is running and the REST API is enabled and reachable from the plugin
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at server/plugin/plg_backend_syncthing/index_helper.go:50 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mickael-kerjean/filestash@78f756eb94 (2026-09-06). Data as JSON: /api/errors/d293f988fd3b43a8. Report an issue: GitHub.