api

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnhanceError

func EnhanceError(err error, path string, params map[string]string) error

EnhanceError checks if an API error matches known patterns and returns an enhanced error message with fix suggestions. If no pattern matches, returns the original error unchanged.

func ValidateEntityType

func ValidateEntityType(entityType string) error

ValidateEntityType checks that an entity type name is safe for use in URL paths.

func WarnSelectDotPaths

func WarnSelectDotPaths(selectExpr string) string

WarnSelectDotPaths checks for dot-path fields in a select expression that are missing 'as' aliases. These fields are silently dropped by the API. Returns a warning message or empty string.

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError represents an error response from the TP API.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL    string
	Token      string
	HTTPClient *http.Client
	Debug      bool
}

Client is the Targetprocess API client.

func NewClient

func NewClient(baseURL, token string, debug bool) *Client

NewClient creates a new API client with retry support.

func (*Client) BuildV2EntityURL

func (c *Client) BuildV2EntityURL(entityType string, id int, selectExpr string) string

BuildV2EntityURL constructs the full v2 URL for a single entity by ID.

func (*Client) BuildV2URL

func (c *Client) BuildV2URL(entityType string, params V2Params) string

BuildV2URL constructs the full v2 URL without executing the request. Useful for --dry-run to inspect the URL that would be called.

func (*Client) CreateEntity

func (c *Client) CreateEntity(ctx context.Context, entityType string, fields map[string]any) (Entity, error)

CreateEntity creates a new entity. Fields are sent as the JSON body.

func (*Client) DeleteEntity added in v0.3.0

func (c *Client) DeleteEntity(ctx context.Context, entityType string, id int) ([]byte, error)

DeleteEntity deletes an entity by type and ID.

func (*Client) GetEntity

func (c *Client) GetEntity(ctx context.Context, entityType string, id int, include []string) (Entity, error)

GetEntity gets a single entity by type and ID.

func (*Client) GetMetaIndex

func (c *Client) GetMetaIndex(ctx context.Context) ([]byte, error)

GetMetaIndex fetches the metadata index (list of all entity types) as XML.

func (*Client) GetTypeMeta

func (c *Client) GetTypeMeta(ctx context.Context, entityType string) ([]byte, error)

GetTypeMeta fetches metadata for a specific entity type as XML.

func (*Client) QueryV2

func (c *Client) QueryV2(ctx context.Context, entityType string, params V2Params) ([]byte, error)

QueryV2 executes a v2 API query and returns raw JSON bytes. entityType is singular (e.g., "UserStory", "Assignable").

func (*Client) QueryV2Entity

func (c *Client) QueryV2Entity(ctx context.Context, entityType string, id int, selectExpr string) ([]byte, error)

QueryV2Entity gets a single entity by ID via v2.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, method, path string, body io.Reader) ([]byte, error)

Raw makes a raw API request. The path can include query parameters.

func (*Client) ResolveEntityType added in v0.4.0

func (c *Client) ResolveEntityType(ctx context.Context, id int) (string, error)

ResolveEntityType resolves the entity type for a given ID via the General endpoint.

func (*Client) SearchEntities

func (c *Client) SearchEntities(ctx context.Context, entityType, where string, include []string, take int, orderBy []string) ([]Entity, error)

SearchEntities searches for entities of the given type.

func (*Client) UpdateEntity

func (c *Client) UpdateEntity(ctx context.Context, entityType string, id int, fields map[string]any) (Entity, error)

UpdateEntity updates an existing entity. TP uses POST for updates.

type Entity

type Entity = map[string]any

Entity represents a generic TP entity as a flexible map.

type V2Params

type V2Params struct {
	Where   string
	Select  string
	OrderBy string
	Take    int
	Skip    int
}

V2Params holds the query parameters for a v2 API request.

Jump to

Keyboard shortcuts

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