{"record":{"id":"043b81e20c101e00","repo":"portainer/portainer","slug":"invalid-environment-identifier-must-be-a-positive","errorCode":null,"errorMessage":"Invalid environment identifier. Must be a positive number","messagePattern":"Invalid environment identifier\\. Must be a positive number","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"api/http/handler/stacks/stack_migrate.go","lineNumber":32,"sourceCode":"\t\"github.com/portainer/portainer/api/stacks/deployments\"\n\t\"github.com/portainer/portainer/api/stacks/stackutils\"\n\thttperror \"github.com/portainer/portainer/pkg/libhttp/error\"\n\t\"github.com/portainer/portainer/pkg/libhttp/request\"\n\t\"github.com/portainer/portainer/pkg/libhttp/response\"\n)\n\ntype stackMigratePayload struct {\n\t// Environment(Endpoint) identifier of the target environment(endpoint) where the stack will be relocated\n\tEndpointID int `example:\"2\" validate:\"required\"`\n\t// Swarm cluster identifier, must match the identifier of the cluster where the stack will be relocated\n\tSwarmID string `example:\"jpofkc0i9uo9wtx1zesuk649w\"`\n\t// If provided will rename the migrated stack\n\tName string `example:\"new-stack\"`\n}\n\nfunc (payload *stackMigratePayload) Validate(r *http.Request) error {\n\tif payload.EndpointID == 0 {\n\t\treturn errors.New(\"Invalid environment identifier. Must be a positive number\")\n\t}\n\treturn nil\n}\n\n// @id StackMigrate\n// @summary Migrate a stack to another environment(endpoint)\n// @description  Migrate a stack from an environment(endpoint) to another environment(endpoint). It will re-create the stack inside the target environment(endpoint) before removing the original stack.\n// @description **Access policy**: authenticated\n// @tags stacks\n// @security ApiKeyAuth\n// @security jwt\n// @produce json\n// @param id path int true \"Stack identifier\"\n// @param endpointId query int false \"Stacks created before version 1.18.0 might not have an associated environment(endpoint) identifier. Use this optional parameter to set the environment(endpoint) identifier used by the stack.\"\n// @param body body stackMigratePayload true \"Stack migration details\"\n// @success 200 {object} portainer.Stack \"Success\"\n// @failure 400 \"Invalid request\"\n// @failure 403 \"Permission denied\"","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/portainer/portainer/blob/17e74456ff6e794b9d5439ec3fa06922aa18a3f8/api/http/handler/stacks/stack_migrate.go#L14-L50","documentation":"Error \"Invalid environment identifier. Must be a positive number\" thrown in portainer/portainer.","triggerScenarios":"Thrown at api/http/handler/stacks/stack_migrate.go:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"17e74456ff6e794b9d5439ec3fa06922aa18a3f8","analyzedAt":"2026-08-26T23:09:01.915Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}