portainer/portainer · error

Invalid environment identifier. Must be a positive number

Error message

Invalid environment identifier. Must be a positive number

What it means

Error "Invalid environment identifier. Must be a positive number" thrown in portainer/portainer.

Source

Thrown at api/http/handler/stacks/stack_migrate.go:32

	"github.com/portainer/portainer/api/stacks/deployments"
	"github.com/portainer/portainer/api/stacks/stackutils"
	httperror "github.com/portainer/portainer/pkg/libhttp/error"
	"github.com/portainer/portainer/pkg/libhttp/request"
	"github.com/portainer/portainer/pkg/libhttp/response"
)

type stackMigratePayload struct {
	// Environment(Endpoint) identifier of the target environment(endpoint) where the stack will be relocated
	EndpointID int `example:"2" validate:"required"`
	// Swarm cluster identifier, must match the identifier of the cluster where the stack will be relocated
	SwarmID string `example:"jpofkc0i9uo9wtx1zesuk649w"`
	// If provided will rename the migrated stack
	Name string `example:"new-stack"`
}

func (payload *stackMigratePayload) Validate(r *http.Request) error {
	if payload.EndpointID == 0 {
		return errors.New("Invalid environment identifier. Must be a positive number")
	}
	return nil
}

// @id StackMigrate
// @summary Migrate a stack to another environment(endpoint)
// @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.
// @description **Access policy**: authenticated
// @tags stacks
// @security ApiKeyAuth
// @security jwt
// @produce json
// @param id path int true "Stack identifier"
// @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."
// @param body body stackMigratePayload true "Stack migration details"
// @success 200 {object} portainer.Stack "Success"
// @failure 400 "Invalid request"
// @failure 403 "Permission denied"

View on GitHub (pinned to 17e74456ff)

When it happens

Trigger: Thrown at api/http/handler/stacks/stack_migrate.go:32 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of portainer/portainer@17e74456ff (2026-08-26). Data as JSON: /api/errors/043b81e20c101e00. Report an issue: GitHub.