Tencent/WeKnora · error
%w: missing api_key
Error message
%w: missing api_key
What it means
parseNotionConfig validates the datasource config's credentials. The credential map must contain an "api_key" entry; if the key is absent the config is rejected with ErrInvalidCredentials wrapped with "missing api_key". Callers can match with errors.Is to detect bad credentials.
Source
Thrown at internal/datasource/connector/notion/types.go:41
const NotionAPIVersion = "2026-03-11"
// DefaultBaseURL is the Notion API base URL.
const DefaultBaseURL = "https://api.notion.com"
// Config holds Notion-specific configuration for the data source connector.
type Config struct {
APIKey string `json:"api_key"` // Internal Integration Token
}
// parseNotionConfig extracts and validates Notion config from DataSourceConfig.
func parseNotionConfig(config *types.DataSourceConfig) (*Config, error) {
if config == nil {
return nil, datasource.ErrInvalidConfig
}
tokenVal, ok := config.Credentials["api_key"]
if !ok {
return nil, fmt.Errorf("%w: missing api_key", datasource.ErrInvalidCredentials)
}
token, ok := tokenVal.(string)
if !ok || token == "" {
return nil, fmt.Errorf("%w: api_key must be a non-empty string", datasource.ErrInvalidCredentials)
}
return &Config{APIKey: token}, nil
}
// --- API response types ---
// notionPage represents a Notion page or database object.
type notionPage struct {
ID string `json:"id"`
Object string `json:"object"` // "page" | "database" | "data_source" (2025-09-03+)
Parent notionParent `json:"parent"`
URL string `json:"url"`
LastEditedTime time.Time `json:"last_edited_time"`View on GitHub (pinned to 988cbb0330)
Solutions
- Set the "api_key" credential to a valid Notion integration token (secret_...)
- Create an integration at notion.so/my-integrations if you have no token
- Verify the env var or config source feeding Credentials is not empty
- Call Validate before Fetch to catch this early
Example fix
// before
creds := map[string]interface{}{}
// after
creds := map[string]interface{}{
"api_key": os.Getenv("NOTION_API_KEY"),
} Defensive patterns
Strategy: validation
Validate before calling
creds := config.Credentials; if creds == nil || creds["api_key"] == nil { return errors.New("api_key credential required") } Type guard
func hasAPIKey(cfg *datasource.Config) bool {
if cfg == nil || cfg.Credentials == nil { return false }
v, ok := cfg.Credentials["api_key"]
return ok && v != nil
} Try / catch
if err := connector.Validate(ctx, cfg); err != nil {
if errors.Is(err, datasource.ErrInvalidCredentials) {
return errors.New("configure NOTION_API_KEY / api_key credential")
}
return err
} Prevention
- Store the Notion integration token in a secret manager and inject it into Credentials
- Check secret injection at startup (fail fast if empty)
- Document the exact credential key name: "api_key"
When it happens
Trigger: Any of Validate, ListResources, FetchAll, FetchIncremental receives a config whose Credentials map has no "api_key" key.
Common situations: Environment variable supplying the Notion token is unset so the credential map omits the key; config file lacks the api_key field; UI saved credentials without the field.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- %w: api_key must be a non-empty string
- invalid sandbox type
- timeout cannot be negative
- memory limit cannot be negative
- CPU limit cannot be negative
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/308c610431f10500.
Report an issue: GitHub.