{"record":{"id":"373aee8177c4cdbf","repo":"kgretzky/evilginx2","slug":"api-key-is-not-set","errorCode":null,"errorMessage":"api key is not set","messagePattern":"api key is not set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/gophish.go","lineNumber":155,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tswitch resp.StatusCode() {\n\tcase 200:\n\t\treturn nil\n\tcase 401:\n\t\treturn fmt.Errorf(\"invalid api key\")\n\tdefault:\n\t\treturn fmt.Errorf(\"status: %d\", resp.StatusCode())\n\t}\n}\n\nfunc (o *GoPhish) validateSetup() error {\n\tif o.AdminUrl == nil {\n\t\treturn fmt.Errorf(\"admin url is not set\")\n\t}\n\tif o.ApiKey == \"\" {\n\t\treturn fmt.Errorf(\"api key is not set\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":137,"sourceCodeEnd":159,"githubUrl":"https://github.com/kgretzky/evilginx2/blob/4c0988a1d9db4d172a185e979a38bfd0efdb5830/core/gophish.go#L137-L159","documentation":"validateSetup is a generic pre-flight validation guard: the GoPhish integration cannot be used because o.ApiKey is the empty string (no API key was configured). It fires before any request is attempted, via Test and the reporting callbacks.","triggerScenarios":"Calling Test, ReportEmailOpened, ReportEmailLinkClicked, or ReportCredentialsSubmitted without having set the API key via the corresponding setter / config entry.","commonSituations":"Admin URL set but key step skipped during setup; config loaded from a template lacking the api_key field; key accidentally cleared or saved as empty string.","solutions":["Set the API key (SetApiKey / config gophish api_key) from the GoPhish Users page","Persist the key in config so it loads on startup","Re-run GoPhish Test to confirm the setup is complete"],"exampleFix":"// before\ngoPhish.SetAdminUrl(adminUrl)\ngoPhish.Test()\n// after\ngoPhish.SetAdminUrl(adminUrl)\ngoPhish.SetApiKey(apiKey)\ngoPhish.Test()","handlingStrategy":"validation","validationCode":"if gp.ApiKey == \"\" {\n    return errors.New(\"configure gophish api key first\")\n}","typeGuard":null,"tryCatchPattern":"if err := gp.ReportEmailOpened(id, email); err != nil {\n    if err.Error() == \"api key is not set\" {\n        // complete setup: SetApiKey then retry\n    }\n}","preventionTips":["Set both AdminUrl and ApiKey together during setup","Never save the key as an empty string","Call Test() once at startup to validate the pair"],"tags":["gophish","auth","api-key","missing-setting"],"backgroundTag":"missing-config-value","analyzedSha":"4c0988a1d9db4d172a185e979a38bfd0efdb5830","analyzedAt":"2026-09-05T19:23:07.238Z","contentChangedAt":"2026-09-05T19:23:07.238Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}