flagsmithapi

package module
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: BSD-3-Clause Imports: 12 Imported by: 1

README

Feature Flag, Remote Config and A/B Testing platform, Flagsmith

Flagsmith is an open source, fully featured, Feature Flag and Remote Config service. Use our hosted API, deploy to your own private cloud, or run on-premise.

Flagsmith Go Admin API Client

This project provides a very(currently) limited access to the Flagsmith Admin APIs using Master API Key.

Documentation

Index

Constants

View Source
const BaseAPIURL = "https://api.flagsmith.com/api/v1"
View Source
const MetadataFieldValueMaxLength = 2000

MetadataFieldValueMaxLength mirrors FIELD_VALUE_MAX_LENGTH in api/metadata/models.py.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(masterAPIKey string, baseURL string) *Client

func (*Client) AddFeatureGroupOwners added in v0.11.0

func (c *Client) AddFeatureGroupOwners(feature *Feature, groupIDs []int64) error

func (*Client) AddFeatureOwners added in v0.5.0

func (c *Client) AddFeatureOwners(feature *Feature, ownerIDs []int64) error

func (*Client) BuildMetadata added in v0.12.0

func (c *Client) BuildMetadata(projectID int64, entity MetadataEntity, values map[string]string) (*[]Metadata, error)

BuildMetadata converts a map of custom field names to values into the wire format, validating each value against its field's configured type.

A nil or empty map yields a non-nil empty slice, which serialises as `"metadata": []`, i.e. an explicit "this entity has no custom field values".

func (*Client) CreateEnvironment added in v0.9.0

func (c *Client) CreateEnvironment(environment *Environment) error

func (*Client) CreateFeature added in v0.1.0

func (c *Client) CreateFeature(feature *Feature) error

func (*Client) CreateFeatureMVOption added in v0.2.0

func (c *Client) CreateFeatureMVOption(featureMVOption *FeatureMultivariateOption) error

func (*Client) CreateFeatureSegment added in v0.4.0

func (c *Client) CreateFeatureSegment(featureSegment *FeatureSegment) error

func (*Client) CreateIdentity added in v0.9.0

func (c *Client) CreateIdentity(environmentKey string, identity *Identity) error

func (*Client) CreateProject added in v0.9.0

func (c *Client) CreateProject(project *Project) error

func (*Client) CreateSegment added in v0.3.0

func (c *Client) CreateSegment(segment *Segment) error

func (*Client) CreateSegmentOverride added in v0.4.0

func (c *Client) CreateSegmentOverride(featureState *FeatureState) error

func (*Client) CreateServerSideEnvKey added in v0.9.0

func (c *Client) CreateServerSideEnvKey(environmentKey string, key *ServerSideEnvKey) error

func (*Client) CreateTag added in v0.8.0

func (c *Client) CreateTag(tag *Tag) error

func (*Client) CreateTrait added in v0.9.0

func (c *Client) CreateTrait(environmentKey string, identityID int64, trait *Trait) error

func (*Client) DeleteEnvironment added in v0.9.0

func (c *Client) DeleteEnvironment(apiKey string) error

func (*Client) DeleteFeature added in v0.1.0

func (c *Client) DeleteFeature(projectID, featureID int64) error

func (*Client) DeleteFeatureMVOption added in v0.2.0

func (c *Client) DeleteFeatureMVOption(projectID, featureID, mvOptionID int64) error

func (*Client) DeleteFeatureSegment added in v0.4.0

func (c *Client) DeleteFeatureSegment(featureSegmentID int64) error

func (*Client) DeleteIdentity added in v0.9.0

func (c *Client) DeleteIdentity(environmentKey string, identityID int64) error

func (*Client) DeleteProject added in v0.9.0

func (c *Client) DeleteProject(projectID int64) error

func (*Client) DeleteSegment added in v0.3.0

func (c *Client) DeleteSegment(projectID, segmentID int64) error

func (*Client) DeleteServerSideEnvKey added in v0.9.0

func (c *Client) DeleteServerSideEnvKey(environmentKey string, keyID int64) error

func (*Client) DeleteTag added in v0.8.0

func (c *Client) DeleteTag(projectID, tagID int64) error

func (*Client) DeleteTrait added in v0.9.0

func (c *Client) DeleteTrait(environmentKey string, identityID int64, traitID int64) error

func (*Client) GetEnvironment added in v0.4.0

func (c *Client) GetEnvironment(apiKey string) (*Environment, error)

func (*Client) GetEnvironmentByUUID added in v0.10.0

func (c *Client) GetEnvironmentByUUID(uuid string) (*Environment, error)

func (*Client) GetEnvironmentFeatureState

func (c *Client) GetEnvironmentFeatureState(environmentKey string, featureID int64) (*FeatureState, error)

Get the feature state associated with the environment for a given feature

func (*Client) GetFeature added in v0.1.0

func (c *Client) GetFeature(featureUUID string) (*Feature, error)

func (*Client) GetFeatureMVOption added in v0.2.0

func (c *Client) GetFeatureMVOption(featureUUID, mvOptionUUID string) (*FeatureMultivariateOption, error)

func (*Client) GetFeatureSegmentByID added in v0.4.0

func (c *Client) GetFeatureSegmentByID(featureSegmentID int64) (*FeatureSegment, error)

func (*Client) GetFeatureState added in v0.4.0

func (c *Client) GetFeatureState(featureStateUUID string) (*FeatureState, error)

func (*Client) GetIdentity added in v0.9.0

func (c *Client) GetIdentity(environmentKey string, identityID int64) (*Identity, error)

func (*Client) GetMetadataFieldResolver added in v0.12.0

func (c *Client) GetMetadataFieldResolver(projectID int64, entity MetadataEntity) (*MetadataFieldResolver, error)

GetMetadataFieldResolver returns a resolver for the given project and entity.

Building one costs three requests: the project, its organisation's content types, and the project's custom field definitions. The result is cached for the lifetime of the client, so a caller writing many entities in one project pays that once. A field created after the first call for a project will not be seen.

func (*Client) GetOrganisationByUUID added in v0.10.0

func (c *Client) GetOrganisationByUUID(orgUUID string) (*Organisation, error)

func (*Client) GetOrganisationUserByEmail added in v0.11.0

func (c *Client) GetOrganisationUserByEmail(orgID int64, email string) (*User, error)

func (*Client) GetOrganisationUsers added in v0.11.0

func (c *Client) GetOrganisationUsers(orgID int64) ([]User, error)

func (*Client) GetProject added in v0.1.0

func (c *Client) GetProject(projectUUID string) (*Project, error)

func (*Client) GetProjectByID added in v0.1.0

func (c *Client) GetProjectByID(projectID int64) (*Project, error)

func (*Client) GetProjectMetadataFields added in v0.12.0

func (c *Client) GetProjectMetadataFields(projectID int64) ([]MetadataField, error)

GetProjectMetadataFields returns every custom field definition visible to a project: the project's own fields plus the inherited organisation level fields.

NOTE: the endpoint's `entity` query param is deliberately not used. It filters which *fields* are returned but does NOT filter each field's nested `model_fields`, so callers have to match on content type regardless. Fetching everything lets a single response serve all three entity types and produce precise "this field exists but is not enabled for features" errors.

func (*Client) GetSegment added in v0.3.0

func (c *Client) GetSegment(segmentUUID string) (*Segment, error)

func (*Client) GetServerSideEnvKeys added in v0.9.0

func (c *Client) GetServerSideEnvKeys(environmentKey string) ([]ServerSideEnvKey, error)

func (*Client) GetSupportedMetadataContentTypes added in v0.12.0

func (c *Client) GetSupportedMetadataContentTypes(organisationID int64) ([]ContentTypeInfo, error)

func (*Client) GetTag added in v0.8.0

func (c *Client) GetTag(projectUUID string, tagUUID string) (*Tag, error)

func (*Client) GetTraits added in v0.9.0

func (c *Client) GetTraits(environmentKey string, identityID int64) ([]Trait, error)

func (*Client) RemoveFeatureGroupOwners added in v0.11.0

func (c *Client) RemoveFeatureGroupOwners(feature *Feature, groupIDs []int64) error

func (*Client) RemoveFeatureOwners added in v0.5.0

func (c *Client) RemoveFeatureOwners(feature *Feature, ownerIDs []int64) error

func (*Client) ResolveMetadataNames added in v0.12.0

func (c *Client) ResolveMetadataNames(projectID int64, entity MetadataEntity, metadata []Metadata) (map[string]string, []int64, error)

ResolveMetadataNames converts wire format metadata back into a map of custom field names to values.

Model field IDs the resolver does not recognise are skipped and returned in unresolved, so that a deleted custom field cannot make a read fail.

func (*Client) UpdateEnvironment added in v0.9.0

func (c *Client) UpdateEnvironment(environment *Environment) error

func (*Client) UpdateFeature added in v0.1.0

func (c *Client) UpdateFeature(feature *Feature) error

func (*Client) UpdateFeatureMVOption added in v0.2.0

func (c *Client) UpdateFeatureMVOption(featureMVOption *FeatureMultivariateOption) error

func (*Client) UpdateFeatureSegmentPriority added in v0.4.0

func (c *Client) UpdateFeatureSegmentPriority(featureSegmentID, priority int64) error

func (*Client) UpdateFeatureState

func (c *Client) UpdateFeatureState(featureState *FeatureState, updateSegmentPriority bool) error

Update the feature state

func (*Client) UpdateProject added in v0.9.0

func (c *Client) UpdateProject(project *Project) error

func (*Client) UpdateSegment added in v0.3.0

func (c *Client) UpdateSegment(segment *Segment) error

func (*Client) UpdateServerSideEnvKey added in v0.9.0

func (c *Client) UpdateServerSideEnvKey(environmentKey string, key *ServerSideEnvKey) error

func (*Client) UpdateTag added in v0.8.0

func (c *Client) UpdateTag(tag *Tag) error

func (*Client) UpdateTrait added in v0.9.0

func (c *Client) UpdateTrait(environmentKey string, identityID int64, trait *Trait) error

type Condition added in v0.3.0

type Condition struct {
	Operator string `json:"operator"`
	Property string `json:"property"`
	Value    string `json:"value"`
}

type ContentTypeInfo added in v0.12.0

type ContentTypeInfo struct {
	ID       int64  `json:"id"`
	AppLabel string `json:"app_label"`
	Model    string `json:"model"`
}

ContentTypeInfo identifies a Django content type. IDs are specific to a Flagsmith installation and must never be hardcoded.

type Environment added in v0.4.0

type Environment struct {
	ID                                int64  `json:"id,omitempty"`
	UUID                              string `json:"uuid,omitempty"`
	Name                              string `json:"name"`
	APIKey                            string `json:"api_key,omitempty"`
	Description                       string `json:"description"`
	ProjectID                         int64  `json:"project"`
	AllowClientTraits                 bool   `json:"allow_client_traits,omitempty"`
	BannerText                        string `json:"banner_text,omitempty"`
	BannerColour                      string `json:"banner_colour,omitempty"`
	HideDisabledFlags                 bool   `json:"hide_disabled_flags,omitempty"`
	HideSensitiveData                 bool   `json:"hide_sensitive_data,omitempty"`
	UseIdentityCompositeKeyForHashing bool   `json:"use_identity_composite_key_for_hashing,omitempty"`
	MinimumChangeRequestApprovals     int64  `json:"minimum_change_request_approvals,omitempty"`

	Metadata *[]Metadata `json:"metadata,omitempty"`
}

type Feature added in v0.1.0

type Feature struct {
	Name           string      `json:"name"`
	UUID           string      `json:"uuid,omitempty"`
	ID             *int64      `json:"id,omitempty"`
	Type           *string     `json:"type,omitempty"`
	Description    *string     `json:"description,omitempty"`
	InitialValue   string      `json:"initial_value,omitempty"`
	DefaultEnabled bool        `json:"default_enabled,omitempty"`
	IsArchived     bool        `json:"is_archived,omitempty"`
	Owners         *[]int64    `json:"owners,omitempty"`
	GroupOwners    *[]int64    `json:"group_owners,omitempty"`
	Tags           []int64     `json:"tags"`
	Metadata       *[]Metadata `json:"metadata,omitempty"`

	ProjectUUID string `json:"-"`
	ProjectID   *int64 `json:"project,omitempty"`
}

func (*Feature) UnmarshalJSON added in v0.5.0

func (f *Feature) UnmarshalJSON(data []byte) error

type FeatureMVOptionNotFoundError added in v0.6.0

type FeatureMVOptionNotFoundError struct {
	// contains filtered or unexported fields
}

func (FeatureMVOptionNotFoundError) Error added in v0.6.0

type FeatureMultivariateOption added in v0.2.0

type FeatureMultivariateOption struct {
	ID                          int64   `json:"id,omitempty"`
	Type                        string  `json:"type"`
	UUID                        string  `json:"uuid,omitempty"`
	FeatureID                   *int64  `json:"feature,omitempty"`
	IntegerValue                *int64  `json:"integer_value,omitempty"`
	StringValue                 *string `json:"string_value,omitempty"`
	BooleanValue                *bool   `json:"boolean_value,omitempty"`
	DefaultPercentageAllocation float64 `json:"default_percentage_allocation"`

	FeatureUUID string `json:"-"`
	ProjectID   *int64 `json:"-"`
}

type FeatureNotFoundError added in v0.6.0

type FeatureNotFoundError struct {
	// contains filtered or unexported fields
}

func (FeatureNotFoundError) Error added in v0.6.0

func (e FeatureNotFoundError) Error() string

type FeatureSegment added in v0.4.0

type FeatureSegment struct {
	ID          *int64 `json:"id,omitempty"`
	Feature     int64  `json:"feature"`
	Segment     *int64 `json:"segment"`
	Environment int64  `json:"environment"`
	Priority    *int64 `json:"priority"`
}

type FeatureState

type FeatureState struct {
	ID                int64              `json:"id,omitempty"`
	UUID              string             `json:"uuid,omitempty"`
	FeatureStateValue *FeatureStateValue `json:"feature_state_value"`
	Enabled           bool               `json:"enabled"`
	Feature           int64              `json:"feature"`
	Environment       *int64             `json:"environment"`
	FeatureSegment    *int64             `json:"feature_segment,omitempty"`

	EnvironmentKey  string `json:"-"`
	Segment         *int64 `json:"-"`
	SegmentPriority *int64 `json:"-"`
}

func (*FeatureState) UnmarshalJSON

func (fs *FeatureState) UnmarshalJSON(data []byte) error

type FeatureStateNotFoundError added in v0.6.0

type FeatureStateNotFoundError struct {
	// contains filtered or unexported fields
}

func (FeatureStateNotFoundError) Error added in v0.6.0

type FeatureStateValue

type FeatureStateValue struct {
	Type         string  `json:"type"`
	StringValue  *string `json:"string_value"`
	IntegerValue *int64  `json:"integer_value"`
	BooleanValue *bool   `json:"boolean_value"`
}

type Identity added in v0.9.0

type Identity struct {
	ID         *int64 `json:"id,omitempty"`
	Identifier string `json:"identifier"`
}

type Metadata added in v0.12.0

type Metadata struct {
	ID         int64  `json:"id,omitempty"`
	ModelField int64  `json:"model_field"`
	FieldValue string `json:"field_value"`
}

FieldValue is always a string on the wire, whatever the custom field's configured type. ModelField is a MetadataModelField ID, not a MetadataField ID.

type MetadataEntity added in v0.12.0

type MetadataEntity string
const (
	MetadataEntityFeature     MetadataEntity = "feature"
	MetadataEntitySegment     MetadataEntity = "segment"
	MetadataEntityEnvironment MetadataEntity = "environment"
)

type MetadataField added in v0.12.0

type MetadataField struct {
	ID           int64                `json:"id"`
	Name         string               `json:"name"`
	Type         string               `json:"type"`
	Description  *string              `json:"description"`
	Organisation int64                `json:"organisation"`
	Project      *int64               `json:"project"`
	ModelFields  []MetadataModelField `json:"model_fields"`
}

MetadataField is a custom field definition. Fields belong to an organisation and may optionally be scoped to a single project.

func (MetadataField) ValidateValue added in v0.12.0

func (f MetadataField) ValidateValue(value string) error

ValidateValue mirrors MetadataField.is_field_value_valid in api/metadata/models.py. The API remains authoritative: unknown field types are accepted here and left for the server to reject.

type MetadataFieldInvalidValueError added in v0.12.0

type MetadataFieldInvalidValueError struct {
	Name      string
	FieldType string
	Value     string
	Reason    string
}

func (MetadataFieldInvalidValueError) Error added in v0.12.0

type MetadataFieldNotBoundError added in v0.12.0

type MetadataFieldNotBoundError struct {
	Name   string
	Entity string
}

func (MetadataFieldNotBoundError) Error added in v0.12.0

type MetadataFieldNotFoundError added in v0.12.0

type MetadataFieldNotFoundError struct {
	Name       string
	Entity     string
	KnownNames []string
}

func (MetadataFieldNotFoundError) Error added in v0.12.0

type MetadataFieldResolver added in v0.12.0

type MetadataFieldResolver struct {
	// contains filtered or unexported fields
}

MetadataFieldResolver maps custom field names to MetadataModelField IDs for a single project and entity type, and back again.

func (*MetadataFieldResolver) BoundNames added in v0.12.0

func (r *MetadataFieldResolver) BoundNames() []string

BoundNames returns the sorted names of the custom fields available for this entity.

func (*MetadataFieldResolver) Field added in v0.12.0

func (r *MetadataFieldResolver) Field(name string) (MetadataField, bool)

Field returns the definition of a custom field bound to this entity.

func (*MetadataFieldResolver) ModelFieldID added in v0.12.0

func (r *MetadataFieldResolver) ModelFieldID(name string) (int64, error)

ModelFieldID returns a MetadataFieldNotBoundError if the field exists in the project but is not enabled for this entity, and a MetadataFieldNotFoundError if it does not exist at all.

func (*MetadataFieldResolver) Name added in v0.12.0

func (r *MetadataFieldResolver) Name(modelFieldID int64) (string, bool)

Name reverse resolves a model field ID. ok is false for IDs the resolver has never seen, for example when the custom field has been deleted since the value was written.

type MetadataModelField added in v0.12.0

type MetadataModelField struct {
	ID          int64 `json:"id"`
	ContentType int64 `json:"content_type"`
}

MetadataModelField binds a custom field to a Django content type, i.e. to features, segments or environments. Its ID is what Metadata.ModelField refers to.

type Organisation added in v0.10.0

type Organisation struct {
	ID                           int64  `json:"id,omitempty"`
	UUID                         string `json:"uuid,omitempty"`
	Name                         string `json:"name"`
	Force2FA                     bool   `json:"force_2fa"`
	RestrictProjectCreateToAdmin bool   `json:"restrict_project_create_to_admin"`
	PersistTraitData             bool   `json:"persist_trait_data"`
}

type Project added in v0.1.0

type Project struct {
	ID                             int64  `json:"id,omitempty"`
	UUID                           string `json:"uuid,omitempty"`
	Name                           string `json:"name"`
	Organisation                   int64  `json:"organisation"`
	HideDisabledFlags              bool   `json:"hide_disabled_flags,omitempty"`
	PreventFlagDefaults            bool   `json:"prevent_flag_defaults,omitempty"`
	OnlyAllowLowerCaseFeatureNames bool   `json:"only_allow_lower_case_feature_names,omitempty"`
	FeatureNameRegex               string `json:"feature_name_regex,omitempty"`
	StaleFlagsLimitDays            int64  `json:"stale_flags_limit_days,omitempty"`
	EnableRealtimeUpdates          bool   `json:"enable_realtime_updates,omitempty"`
	EnforceFeatureOwners           *bool  `json:"enforce_feature_owners,omitempty"`
}

type Rule added in v0.3.0

type Rule struct {
	Type       string      `json:"type"`
	Rules      []Rule      `json:"rules,omitempty"`
	Conditions []Condition `json:"conditions,omitempty"`
}

type Segment added in v0.3.0

type Segment struct {
	ID          *int64      `json:"id,omitempty"`
	UUID        string      `json:"uuid,omitempty"`
	Name        string      `json:"name"`
	Description *string     `json:"description,omitempty"`
	ProjectID   *int64      `json:"project"`
	ProjectUUID string      `json:"-"`
	FeatureID   *int64      `json:"feature,omitempty"`
	Rules       []Rule      `json:"rules"`
	Metadata    *[]Metadata `json:"metadata,omitempty"`
}

type SegmentNotFoundError added in v0.6.0

type SegmentNotFoundError struct {
	// contains filtered or unexported fields
}

func (SegmentNotFoundError) Error added in v0.6.0

func (e SegmentNotFoundError) Error() string

type ServerSideEnvKey added in v0.9.0

type ServerSideEnvKey struct {
	ID        int64      `json:"id,omitempty"`
	Active    bool       `json:"active"`
	Name      string     `json:"name,omitempty"`
	Key       string     `json:"key,omitempty"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
}

type Tag added in v0.8.0

type Tag struct {
	ID          *int64  `json:"id,omitempty"`
	UUID        string  `json:"uuid,omitempty"`
	Name        string  `json:"label"`
	Description *string `json:"description"`
	Colour      string  `json:"color"`

	ProjectUUID string `json:"-"`
	ProjectID   *int64 `json:"project,omitempty"`
}

type Trait added in v0.9.0

type Trait struct {
	ID           int64    `json:"id,omitempty"`
	TraitKey     string   `json:"trait_key"`
	ValueType    string   `json:"value_type"`
	IntegerValue *int     `json:"integer_value,omitempty"`
	StringValue  *string  `json:"string_value,omitempty"`
	BooleanValue *bool    `json:"boolean_value,omitempty"`
	FloatValue   *float64 `json:"float_value,omitempty"`
}

type User added in v0.11.0

type User struct {
	ID         int64  `json:"id"`
	Email      string `json:"email"`
	FirstName  string `json:"first_name"`
	LastName   string `json:"last_name"`
	LastLogin  string `json:"last_login"`
	DateJoined string `json:"date_joined"`
	UUID       string `json:"uuid"`
	Role       string `json:"role"`
}

type UserNotFoundError added in v0.11.0

type UserNotFoundError struct {
	// contains filtered or unexported fields
}

func (UserNotFoundError) Error added in v0.11.0

func (e UserNotFoundError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL