snipeit

package module
v0.0.0-campustech Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 16 Imported by: 2

README

go-snipeit

A Go client library for the Snipe-IT Asset Management API.

Documentation

Overview

Package snipeit provides a client for the Snipe-IT Asset Management API.

Package snipeit provides data models for interacting with the Snipe-IT API.

Package snipeit provides a client for the Snipe-IT Asset Management API.

Package snipeit provides a Go client for interacting with the Snipe-IT Asset Management API.

Snipe-IT is an open-source IT asset management system that allows for tracking hardware, software, and accessories. This client library provides a simple interface to interact with the Snipe-IT REST API.

Usage:

client, err := snipeit.NewClient("https://your-snipeit-instance.com", "your-api-token")
if err != nil {
    log.Fatalf("Error creating client: %v", err)
}

// List assets
assets, _, err := client.Assets.List(nil)
if err != nil {
    log.Fatalf("Error listing assets: %v", err)
}

// Get a specific asset
asset, _, err := client.Assets.Get(1)
if err != nil {
    log.Fatalf("Error getting asset: %v", err)
}

API documentation: https://snipe-it.readme.io/reference/api-overview

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// AssetTag is a unique identifier for the asset in your organization
	AssetTag string `json:"asset_tag"`

	// Serial is the manufacturer's serial number
	Serial string `json:"serial"`

	// Model specifies what model the asset is
	Model Model `json:"model"`

	// ModelNumber is the manufacturer's model number
	ModelNumber string `json:"model_number,omitempty"`

	// StatusLabel indicates the current status (e.g., "Ready to Deploy", "Deployed")
	StatusLabel StatusLabel `json:"status_label"`

	// Category of the asset (e.g., "Laptop", "Monitor")
	Category Category `json:"category"`

	// Manufacturer of the asset
	Manufacturer Manufacturer `json:"manufacturer"`

	// Supplier from whom the asset was purchased
	Supplier Supplier `json:"supplier,omitempty"`

	// Location where the asset is physically located
	Location Location `json:"location,omitempty"`

	// PurchaseDate when the asset was purchased
	PurchaseDate *SnipeTime `json:"purchase_date,omitempty"`

	// PurchaseCost of the asset
	PurchaseCost string `json:"purchase_cost,omitempty"`

	// WarrantyMonths is the length of the warranty in months.
	// Uses FlexInt because the Snipe-IT API may return this as a string.
	WarrantyMonths FlexInt `json:"warranty_months,omitempty"`

	// User to whom the asset is assigned (if any).
	// Uses FlexUser because the API returns a full User object on GET but
	// just a user ID number on create/update response payloads.
	User *FlexUser `json:"assigned_to,omitempty"`

	// AssignedType indicates what type of entity the asset is assigned to
	// (e.g., "user", "location", "asset")
	AssignedType string `json:"assigned_type,omitempty"`
}

Asset represents a Snipe-IT hardware asset. Assets are the primary items tracked in Snipe-IT, such as laptops, phones, monitors, etc.

func (Asset) MarshalJSON

func (a Asset) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Asset. The Snipe-IT API returns nested objects for related resources (model, status_label, category, etc.) on GET, but expects flat ID fields (model_id, status_id, category_id, etc.) on POST/PUT. This method converts the nested objects to flat IDs and also flattens custom fields to top-level keys.

func (*Asset) UnmarshalJSON

func (a *Asset) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Asset. The Snipe-IT API returns custom fields as a nested object under "custom_fields" where each entry has "field" (db column name) and "value". This method extracts those into the CustomFields map keyed by db column name, making them easy to compare with write-side values.

type AssetCreateResponse

type AssetCreateResponse struct {
	Response
	Payload Asset `json:"payload"`
}

AssetCreateResponse represents the API response for asset create and update operations. Unlike GET which returns the asset directly, create/update responses wrap the result in a status/payload envelope:

{"status":"success","messages":"...","payload":{...}}
{"status":"error","messages":{...}}

type AssetResponse

type AssetResponse struct {
	Asset
}

AssetResponse represents the API response for a single asset. The single asset endpoint returns the asset data directly, not wrapped in a payload field.

type AssetsResponse

type AssetsResponse struct {
	Response
	// Rows contains the list of Asset objects
	Rows []Asset `json:"rows"`
}

AssetsResponse represents the API response for multiple assets. It embeds the standard Response struct and adds a Rows field that contains a slice of Assets.

type AssetsService

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

AssetsService handles communication with the asset-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware

func (*AssetsService) Checkin

func (s *AssetsService) Checkin(id int, checkin map[string]interface{}) (*AssetCreateResponse, *http.Response, error)

Checkin returns an asset from a user, location, or asset it was assigned to.

id is the unique identifier of the asset to check in. checkin is a map containing checkin parameters, such as: - note: Note about the checkin - location_id: ID of the location to assign after checkin - status_id: ID of the status to assign after checkin - checkin_at: Date of checkin (YYYY-MM-DD format)

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-checkin

func (*AssetsService) CheckinContext

func (s *AssetsService) CheckinContext(ctx context.Context, id int, checkin map[string]interface{}) (*AssetCreateResponse, *http.Response, error)

CheckinContext returns an asset with the provided context.

ctx is the context for the request. id is the unique identifier of the asset to check in. checkin is a map containing checkin parameters, such as: - note: Note about the checkin - location_id: ID of the location to assign after checkin - status_id: ID of the status to assign after checkin - checkin_at: Date of checkin (YYYY-MM-DD format)

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-checkin

func (*AssetsService) Checkout

func (s *AssetsService) Checkout(id int, checkout map[string]interface{}) (*AssetCreateResponse, *http.Response, error)

Checkout assigns an asset to a user, location, or another asset.

id is the unique identifier of the asset to check out. checkout is a map containing checkout parameters, such as: - assigned_user: ID of the user to assign the asset to - assigned_asset: ID of the asset to assign this asset to - assigned_location: ID of the location to assign the asset to - checkout_at: Date of checkout (YYYY-MM-DD format) - expected_checkin: Expected checkin date (YYYY-MM-DD format) - note: Note about the checkout

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-checkout

func (*AssetsService) CheckoutContext

func (s *AssetsService) CheckoutContext(ctx context.Context, id int, checkout map[string]interface{}) (*AssetCreateResponse, *http.Response, error)

CheckoutContext assigns an asset to a user, location, or another asset with the provided context.

ctx is the context for the request. id is the unique identifier of the asset to check out. checkout is a map containing checkout parameters, such as: - assigned_user: ID of the user to assign the asset to - assigned_asset: ID of the asset to assign this asset to - assigned_location: ID of the location to assign the asset to - checkout_at: Date of checkout (YYYY-MM-DD format) - expected_checkin: Expected checkin date (YYYY-MM-DD format) - note: Note about the checkout

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-checkout

func (*AssetsService) Create

func (s *AssetsService) Create(asset Asset) (*AssetCreateResponse, *http.Response, error)

Create creates a new asset in Snipe-IT.

asset must contain the required fields: - Model.ID: The ID of the model - StatusLabel.ID: The ID of the status label - AssetTag: A unique asset tag

Other important fields that should be considered: - Name: A name for the asset - Serial: The manufacturer's serial number

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-create

func (*AssetsService) CreateContext

func (s *AssetsService) CreateContext(ctx context.Context, asset Asset) (*AssetCreateResponse, *http.Response, error)

CreateContext creates a new asset in Snipe-IT with the provided context.

ctx is the context for the request. asset must contain the required fields: - Model.ID: The ID of the model - StatusLabel.ID: The ID of the status label - AssetTag: A unique asset tag

Other important fields that should be considered: - Name: A name for the asset - Serial: The manufacturer's serial number

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-create

func (*AssetsService) Delete

func (s *AssetsService) Delete(id int) (*http.Response, error)

Delete deletes an asset from Snipe-IT.

id is the unique identifier of the asset to delete. This operation soft-deletes the asset in Snipe-IT.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-delete

func (*AssetsService) DeleteContext

func (s *AssetsService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes an asset from Snipe-IT with the provided context.

ctx is the context for the request. id is the unique identifier of the asset to delete. This operation soft-deletes the asset in Snipe-IT.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-delete

func (*AssetsService) Get

func (s *AssetsService) Get(id int) (*AssetResponse, *http.Response, error)

Get fetches a single asset by its ID.

id is the unique identifier of the asset to retrieve.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-by-id

func (*AssetsService) GetAssetBySerial

func (s *AssetsService) GetAssetBySerial(serial string) (*AssetsResponse, *http.Response, error)

GetAssetBySerial fetches assets by serial number.

serial is the manufacturer's serial number of the asset to retrieve. Note: This endpoint returns a list response, not a single asset, because serial numbers might not be unique in Snipe-IT.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-by-serial

func (*AssetsService) GetAssetBySerialContext

func (s *AssetsService) GetAssetBySerialContext(ctx context.Context, serial string) (*AssetsResponse, *http.Response, error)

GetAssetBySerialContext fetches assets by serial number with the provided context.

ctx is the context for the request. serial is the manufacturer's serial number of the asset to retrieve. Note: This endpoint returns a list response, not a single asset, because serial numbers might not be unique in Snipe-IT.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-by-serial

func (*AssetsService) GetContext

func (s *AssetsService) GetContext(ctx context.Context, id int) (*AssetResponse, *http.Response, error)

GetContext fetches a single asset by its ID with the provided context.

ctx is the context for the request. id is the unique identifier of the asset to retrieve.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-by-id

func (*AssetsService) List

List returns a list of assets with pagination options.

opts can be used to customize the response with pagination, search, and sorting. If opts is nil, default pagination values will be used.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-list

func (*AssetsService) ListContext

func (s *AssetsService) ListContext(ctx context.Context, opts *ListOptions) (*AssetsResponse, *http.Response, error)

ListContext returns a list of assets with the provided context and pagination options.

ctx is the context for the request. opts can be used to customize the response with pagination, search, and sorting. If opts is nil, default pagination values will be used.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-list

func (*AssetsService) Patch

func (s *AssetsService) Patch(id int, asset Asset) (*AssetCreateResponse, *http.Response, error)

Patch partially updates an existing asset in Snipe-IT using HTTP PATCH. Unlike Update (which uses PUT), Patch only modifies the fields included in the request body, leaving all other fields unchanged.

id is the unique identifier of the asset to update. asset contains only the fields to modify.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-partial-update

func (*AssetsService) PatchContext

func (s *AssetsService) PatchContext(ctx context.Context, id int, asset Asset) (*AssetCreateResponse, *http.Response, error)

PatchContext partially updates an existing asset with the provided context.

ctx is the context for the request. id is the unique identifier of the asset to update. asset contains only the fields to modify.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-partial-update

func (*AssetsService) Update

func (s *AssetsService) Update(id int, asset Asset) (*AssetCreateResponse, *http.Response, error)

Update updates an existing asset in Snipe-IT.

id is the unique identifier of the asset to update. asset contains the fields to update. You only need to include the fields you want to modify; other fields can be omitted.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-update

func (*AssetsService) UpdateContext

func (s *AssetsService) UpdateContext(ctx context.Context, id int, asset Asset) (*AssetCreateResponse, *http.Response, error)

UpdateContext updates an existing asset in Snipe-IT with the provided context.

ctx is the context for the request. id is the unique identifier of the asset to update. asset contains the fields to update. You only need to include the fields you want to modify; other fields can be omitted.

Snipe-IT API docs: https://snipe-it.readme.io/reference/hardware-update

type Category

type Category struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// Type of category (e.g., "asset", "accessory", "consumable", "component")
	Type string `json:"type"`

	// EULA indicates if this category requires a EULA acceptance
	EULA bool `json:"eula,omitempty"`

	// Checkin indicates if email should be sent on checkin
	Checkin bool `json:"checkin_email,omitempty"`

	// Checkout indicates if email should be sent on checkout
	Checkout bool `json:"checkout_email,omitempty"`

	// RequireMAAC indicates if manager acceptance is required
	RequireMAAC bool `json:"require_acceptance,omitempty"`

	// AssetsCount is the number of assets in this category
	AssetsCount int `json:"assets_count,omitempty"`

	// ModelsCount is the number of models in this category
	ModelsCount int `json:"models_count,omitempty"`
}

Category represents a Snipe-IT category. Categories group models into logical collections (e.g., "Laptops", "Monitors").

type Client

type Client struct {

	// Base URL for API requests
	BaseURL *url.URL

	// Services for different parts of the Snipe-IT API
	// Assets is the service for interacting with the assets endpoint
	Assets *AssetsService

	// Locations is the service for interacting with the locations endpoint
	Locations *LocationsService

	// StatusLabels is the service for interacting with the status labels endpoint
	StatusLabels *StatusLabelsService

	// Fields is the service for interacting with the custom fields endpoint
	Fields *FieldsService

	// Fieldsets is the service for interacting with the custom fieldsets endpoint
	Fieldsets *FieldsetsService

	// Models is the service for interacting with the models endpoint
	Models *ModelsService

	// Users is the service for interacting with the users endpoint
	Users *UsersService

	// Suppliers is the service for interacting with the suppliers endpoint
	Suppliers *SuppliersService
	// contains filtered or unexported fields
}

Client manages communication with the Snipe-IT API.

Each service of the Snipe-IT API is exposed as a field on the Client struct. For example, to access the assets endpoint, use client.Assets.

func NewClient

func NewClient(baseURL, token string) (*Client, error)

NewClient returns a new Snipe-IT API client.

baseURL is the base URL of your Snipe-IT instance (e.g., "https://assets.example.com"). token is your Snipe-IT API token, which can be generated in the Snipe-IT web interface under Admin > API Keys.

This function uses the default http.Client. If you need to customize the HTTP client, use NewClientWithHTTPClient instead.

If baseURL does not have a trailing slash, one is added automatically.

Returns an error if baseURL is invalid or if either baseURL or token is empty.

func NewClientWithHTTPClient

func NewClientWithHTTPClient(httpClient *http.Client, baseURL, token string) (*Client, error)

NewClientWithHTTPClient returns a new Snipe-IT API client using the provided HTTP client.

httpClient is the HTTP client to use for making API requests. baseURL is the base URL of your Snipe-IT instance. token is your Snipe-IT API token.

This function allows you to customize the HTTP client used by the Snipe-IT client, which is useful for setting custom timeouts, transport options, or proxies.

If baseURL does not have a trailing slash, one is added automatically.

Returns an error if baseURL is invalid or if either baseURL or token is empty.

func NewClientWithOptions

func NewClientWithOptions(baseURL, token string, options *ClientOptions) (*Client, error)

NewClientWithOptions returns a new Snipe-IT API client with advanced configuration options.

baseURL is the base URL of your Snipe-IT instance (e.g., "https://assets.example.com"). token is your Snipe-IT API token, which can be generated in the Snipe-IT web interface. options allows for configuring rate limiting, retries, and HTTP client settings.

If options is nil, default settings will be used. If options.HTTPClient is nil, http.DefaultClient will be used. If options.RateLimiter is nil, no rate limiting will be applied. If options.RetryPolicy is nil but options.DisableRetries is false, DefaultRetryPolicy will be used.

If baseURL does not have a trailing slash, one is added automatically.

Returns an error if baseURL is invalid or if either baseURL or token is empty.

func (*Client) AddOptions

func (c *Client) AddOptions(s string, opt interface{}) (string, error)

AddOptions adds the parameters in opt as URL query parameters to s.

s is the URL string to which the query parameters will be added. opt is a struct whose fields contain "url" tags that define the query parameter names.

For example, if opt is a struct with a field `Limit int `url:"limit,omitempty"`, and Limit is set to 10, the resulting URL will have ?limit=10 appended.

This method relies on the github.com/google/go-querystring package to convert the struct fields to query parameters.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response.

req is the HTTP request to send. v is the destination into which the response JSON will be unmarshaled. If v implements the io.Writer interface, the raw response body will be written to it without attempting to parse it as JSON.

If the response status code is not in the 2xx range, an ErrorResponse is returned. Otherwise, if v is not nil, the response body is JSON decoded into v.

The provided request and returned response are for debugging purposes only and should not be directly modified.

func (*Client) DoContext

func (c *Client) DoContext(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

DoContext sends an API request with the provided context and returns the API response.

ctx is the context for the request. If it is nil, a default context will be used. req is the HTTP request to send. v is the destination into which the response JSON will be unmarshaled. If v implements the io.Writer interface, the raw response body will be written to it without attempting to parse it as JSON.

If the response status code is not in the 2xx range, an ErrorResponse is returned. Otherwise, if v is not nil, the response body is JSON decoded into v.

The provided request and returned response are for debugging purposes only and should not be directly modified.

func (*Client) DoWithOptions

func (c *Client) DoWithOptions(req *http.Request, v interface{}, opts *RequestOptions) (*http.Response, error)

DoWithOptions sends an API request with the provided request options and returns the API response.

req is the HTTP request to send. v is the destination into which the response JSON will be unmarshaled. opts are optional settings for this specific request.

If opts is nil, the client's default options will be used. If opts.Context is nil, the request's context will be used.

If the response status code is not in the 2xx range, an ErrorResponse is returned. Otherwise, if v is not nil, the response body is JSON decoded into v.

The provided request and returned response are for debugging purposes only and should not be directly modified.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. This is an exported wrapper around newRequest for use by callers that need to make direct API calls beyond the built-in services.

type ClientOptions

type ClientOptions struct {
	// HTTPClient is the HTTP client to use for making requests.
	// If nil, http.DefaultClient will be used.
	HTTPClient *http.Client

	// RateLimiter controls the rate at which requests are made to the API.
	// If nil, no rate limiting will be applied.
	RateLimiter RateLimiter

	// RetryPolicy defines how failed requests should be retried.
	// If nil, DefaultRetryPolicy will be used.
	RetryPolicy *RetryPolicy

	// DisableRetries, if true, disables automatic retries for failed requests.
	DisableRetries bool

	// Logger enables debug logging of HTTP requests and responses.
	// If nil, no logging is performed.
	Logger Logger
}

ClientOptions contains options for configuring the Snipe-IT client.

type CommonFields

type CommonFields struct {
	// ID is the unique identifier for the resource
	ID int `json:"id"`

	// CreatedAt is when the resource was created
	CreatedAt *SnipeTime `json:"created_at"`

	// UpdatedAt is when the resource was last updated
	UpdatedAt *SnipeTime `json:"updated_at"`

	// DeletedAt is when the resource was soft-deleted (if applicable)
	DeletedAt *SnipeTime `json:"deleted_at,omitempty"`

	// Name of the resource
	Name string `json:"name"`

	// Notes associated with the resource
	Notes string `json:"notes,omitempty"`

	// Available indicates if the resource is available for checkout
	Available bool `json:"available"`

	// Deleted indicates if the resource has been soft-deleted
	Deleted bool `json:"deleted"`

	// Image is a URL to the image associated with the resource
	Image string `json:"image,omitempty"`

	// CustomFields contains any custom fields defined for the resource.
	// When reading from the API, Snipe-IT returns these as a nested object
	// under "custom_fields". When writing, they must be sent as top-level
	// keys (e.g. "_snipeit_ram_2"). The Asset type's MarshalJSON handles
	// this flattening automatically.
	CustomFields map[string]string `json:"-"`
}

CommonFields contains fields that are common across many Snipe-IT resource types. This is embedded in other model structs to avoid repetition.

type ErrorResponse

type ErrorResponse struct {
	// Response is the HTTP response that generated the error
	Response *http.Response

	// Message is the error message returned by the Snipe-IT API
	Message string `json:"message"`
}

ErrorResponse represents an error response from the Snipe-IT API.

Snipe-IT API error responses typically contain a message explaining what went wrong, which is captured in the Message field.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error returns a string representation of the error. It implements the error interface.

type Field

type Field struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// DBColumnName is the database column name (e.g. "_snipeit_ram_2")
	DBColumnName string `json:"db_column_name,omitempty"`

	// Element is the form element type (e.g. "text", "textarea", "checkbox")
	Element string `json:"element,omitempty"`

	// Format is the validation format (e.g. "numeric", "BOOLEAN", "URL")
	Format string `json:"format,omitempty"`

	// HelpText is displayed to users when filling in the field
	HelpText string `json:"help_text,omitempty"`

	// FieldValues contains possible values for list-type fields
	FieldValues string `json:"field_values,omitempty"`

	// FieldValuesArray contains possible values as a slice
	FieldValuesArray []string `json:"field_values_array,omitempty"`

	// ShowInListView indicates if the field is shown in asset list views.
	// Uses FlexBool because the Snipe-IT API returns this as 0/1 instead of bool.
	ShowInListView FlexBool `json:"show_in_listview,omitempty"`

	// Type is the field type
	Type string `json:"type,omitempty"`
}

Field represents a Snipe-IT custom field. Custom fields extend the data stored on assets beyond the built-in fields.

type FieldResponse

type FieldResponse struct {
	Response
	Payload Field `json:"payload"`
}

FieldResponse represents the API response for a single field.

type FieldsResponse

type FieldsResponse struct {
	Response
	Rows []Field `json:"rows"`
}

FieldsResponse represents the API response for multiple fields.

type FieldsService

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

FieldsService handles communication with the custom field-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/fields

func (*FieldsService) Associate

func (s *FieldsService) Associate(fieldID, fieldsetID int) (*http.Response, error)

Associate associates a custom field with a fieldset.

func (*FieldsService) AssociateContext

func (s *FieldsService) AssociateContext(ctx context.Context, fieldID, fieldsetID int) (*http.Response, error)

AssociateContext associates a custom field with a fieldset with the provided context.

func (*FieldsService) Create

func (s *FieldsService) Create(field Field) (*FieldResponse, *http.Response, error)

Create creates a new custom field in Snipe-IT.

func (*FieldsService) CreateContext

func (s *FieldsService) CreateContext(ctx context.Context, field Field) (*FieldResponse, *http.Response, error)

CreateContext creates a new custom field in Snipe-IT with the provided context.

func (*FieldsService) Delete

func (s *FieldsService) Delete(id int) (*http.Response, error)

Delete deletes a custom field from Snipe-IT.

func (*FieldsService) DeleteContext

func (s *FieldsService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a custom field from Snipe-IT with the provided context.

func (*FieldsService) Get

func (s *FieldsService) Get(id int) (*FieldResponse, *http.Response, error)

Get fetches a single custom field by its ID.

func (*FieldsService) GetContext

func (s *FieldsService) GetContext(ctx context.Context, id int) (*FieldResponse, *http.Response, error)

GetContext fetches a single custom field by its ID with the provided context.

func (*FieldsService) List

List returns a list of custom fields with pagination options.

func (*FieldsService) ListContext

func (s *FieldsService) ListContext(ctx context.Context, opts *ListOptions) (*FieldsResponse, *http.Response, error)

ListContext returns a list of custom fields with the provided context and pagination options.

func (*FieldsService) Update

func (s *FieldsService) Update(id int, field Field) (*FieldResponse, *http.Response, error)

Update updates an existing custom field in Snipe-IT.

func (*FieldsService) UpdateContext

func (s *FieldsService) UpdateContext(ctx context.Context, id int, field Field) (*FieldResponse, *http.Response, error)

UpdateContext updates an existing custom field in Snipe-IT with the provided context.

type Fieldset

type Fieldset struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// Fields contains the custom fields in this fieldset as raw JSON.
	// The Snipe-IT API may return this as an array of objects (when fields exist)
	// or as an empty object {} (when no fields are associated), so we use
	// json.RawMessage to handle both cases gracefully.
	Fields json.RawMessage `json:"fields,omitempty"`

	// ModelsCount is the number of models using this fieldset
	ModelsCount int `json:"models_count,omitempty"`
}

Fieldset represents a Snipe-IT custom fieldset. Fieldsets group custom fields together and are associated with models.

type FieldsetResponse

type FieldsetResponse struct {
	Response
	Payload Fieldset `json:"payload"`
}

FieldsetResponse represents the API response for a single fieldset.

type FieldsetsResponse

type FieldsetsResponse struct {
	Response
	Rows []Fieldset `json:"rows"`
}

FieldsetsResponse represents the API response for multiple fieldsets.

type FieldsetsService

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

FieldsetsService handles communication with the custom fieldset-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/fieldsets

func (*FieldsetsService) Create

func (s *FieldsetsService) Create(fieldset Fieldset) (*FieldsetResponse, *http.Response, error)

Create creates a new custom fieldset in Snipe-IT.

func (*FieldsetsService) CreateContext

func (s *FieldsetsService) CreateContext(ctx context.Context, fieldset Fieldset) (*FieldsetResponse, *http.Response, error)

CreateContext creates a new custom fieldset in Snipe-IT with the provided context.

func (*FieldsetsService) Delete

func (s *FieldsetsService) Delete(id int) (*http.Response, error)

Delete deletes a custom fieldset from Snipe-IT.

func (*FieldsetsService) DeleteContext

func (s *FieldsetsService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a custom fieldset from Snipe-IT with the provided context.

func (*FieldsetsService) Get

Get fetches a single custom fieldset by its ID.

func (*FieldsetsService) GetContext

func (s *FieldsetsService) GetContext(ctx context.Context, id int) (*FieldsetResponse, *http.Response, error)

GetContext fetches a single custom fieldset by its ID with the provided context.

func (*FieldsetsService) List

List returns a list of custom fieldsets with pagination options.

func (*FieldsetsService) ListContext

ListContext returns a list of custom fieldsets with the provided context and pagination options.

func (*FieldsetsService) Update

func (s *FieldsetsService) Update(id int, fieldset Fieldset) (*FieldsetResponse, *http.Response, error)

Update updates an existing custom fieldset in Snipe-IT.

func (*FieldsetsService) UpdateContext

func (s *FieldsetsService) UpdateContext(ctx context.Context, id int, fieldset Fieldset) (*FieldsetResponse, *http.Response, error)

UpdateContext updates an existing custom fieldset in Snipe-IT with the provided context.

type FlexBool

type FlexBool bool

FlexBool handles JSON fields that may be returned as a bool, an int (0/1), or a string ("true"/"false"/"0"/"1"). The Snipe-IT API returns some boolean fields as integers.

func (FlexBool) Bool

func (fb FlexBool) Bool() bool

Bool returns the underlying bool value.

func (FlexBool) MarshalJSON

func (fb FlexBool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler, always encoding as a JSON boolean.

func (*FlexBool) UnmarshalJSON

func (fb *FlexBool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler, accepting bool, int (0/1), and string ("true"/"false"/"0"/"1") representations.

type FlexInt

type FlexInt int

FlexInt handles JSON fields that may be returned as either a string or an int. The Snipe-IT API is inconsistent about numeric field types — some fields like warranty_months may be returned as a quoted string (e.g. "36") instead of a bare integer.

func (FlexInt) Int

func (fi FlexInt) Int() int

Int returns the underlying int value.

func (FlexInt) MarshalJSON

func (fi FlexInt) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler, always encoding as a bare integer.

func (*FlexInt) UnmarshalJSON

func (fi *FlexInt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler, accepting both integer and string representations of a number.

type FlexMessage

type FlexMessage string

FlexMessage handles the Snipe-IT API's "messages" field which may be returned as a plain string (e.g. "Asset does not exist.") or as an object with field-level validation errors (e.g. {"model_id":["The model id field is required."]}).

func (FlexMessage) String

func (fm FlexMessage) String() string

String returns the message as a string.

func (*FlexMessage) UnmarshalJSON

func (fm *FlexMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for FlexMessage.

type FlexUser

type FlexUser struct {
	User
}

FlexUser handles the Snipe-IT API's polymorphic "assigned_to" field. On GET responses, the API returns a full User object. On create/update response payloads, the API returns just the user's ID as a number, or null.

func (FlexUser) MarshalJSON

func (fu FlexUser) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for FlexUser. Always marshals as just the user ID for write operations.

func (*FlexUser) UnmarshalJSON

func (fu *FlexUser) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for FlexUser.

type ListOptions

type ListOptions struct {
	// Page number for paginated results (1-based)
	Page int `url:"page,omitempty"`

	// Limit sets the maximum number of items to return per page
	Limit int `url:"limit,omitempty"`

	// Offset is the number of items to skip before starting to collect results
	Offset int `url:"offset,omitempty"`

	// Sort specifies the field to sort results by (e.g., "id", "name")
	Sort string `url:"sort,omitempty"`

	// SortDir specifies the sort direction, either "asc" or "desc"
	SortDir string `url:"sort_dir,omitempty"`

	// Search is a search term to filter results
	Search string `url:"search,omitempty"`
}

ListOptions specifies common options for paginated API methods. These options are used to control pagination, sorting, and filtering of list results.

type Location

type Location struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// Address line 1
	Address string `json:"address,omitempty"`

	// Address line 2
	Address2 string `json:"address2,omitempty"`

	// City name
	City string `json:"city,omitempty"`

	// State or province
	State string `json:"state,omitempty"`

	// Country name
	Country string `json:"country,omitempty"`

	// Zip or postal code
	Zip string `json:"zip,omitempty"`

	// Currency used at this location
	Currency string `json:"currency,omitempty"`

	// ParentID is the ID of the parent location (for hierarchical locations)
	ParentID int `json:"parent_id,omitempty"`

	// Parent is the parent location object (for hierarchical locations)
	Parent *Location `json:"parent,omitempty"`

	// Children are the child locations of this location
	Children []Location `json:"children,omitempty"`

	// AssetsCount is the number of assets at this location
	AssetsCount int `json:"assets_count,omitempty"`
}

Location represents a Snipe-IT location. Locations are physical places where assets can be assigned or checked out to.

type LocationResponse

type LocationResponse struct {
	Response
	Payload Location `json:"payload"`
}

LocationResponse represents the API response for a single location.

type LocationsResponse

type LocationsResponse struct {
	Response
	Rows []Location `json:"rows"`
}

LocationsResponse represents the API response for multiple locations.

type LocationsService

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

LocationsService handles communication with the location-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/locations

func (*LocationsService) Create

func (s *LocationsService) Create(location Location) (*LocationResponse, *http.Response, error)

Create creates a new location in Snipe-IT.

func (*LocationsService) CreateContext

func (s *LocationsService) CreateContext(ctx context.Context, location Location) (*LocationResponse, *http.Response, error)

CreateContext creates a new location in Snipe-IT with the provided context.

func (*LocationsService) Delete

func (s *LocationsService) Delete(id int) (*http.Response, error)

Delete deletes a location from Snipe-IT.

func (*LocationsService) DeleteContext

func (s *LocationsService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a location from Snipe-IT with the provided context.

func (*LocationsService) Get

Get fetches a single location by its ID.

func (*LocationsService) GetContext

func (s *LocationsService) GetContext(ctx context.Context, id int) (*LocationResponse, *http.Response, error)

GetContext fetches a single location by its ID with the provided context.

func (*LocationsService) List

List returns a list of locations with pagination options.

func (*LocationsService) ListContext

ListContext returns a list of locations with the provided context and pagination options.

func (*LocationsService) Update

func (s *LocationsService) Update(id int, location Location) (*LocationResponse, *http.Response, error)

Update updates an existing location in Snipe-IT.

func (*LocationsService) UpdateContext

func (s *LocationsService) UpdateContext(ctx context.Context, id int, location Location) (*LocationResponse, *http.Response, error)

UpdateContext updates an existing location in Snipe-IT with the provided context.

type Logger

type Logger interface {
	// LogRequest is called before each HTTP request is sent.
	// method is the HTTP method, url is the full request URL, and body is the
	// request body (nil for requests with no body).
	LogRequest(method, url string, body []byte)

	// LogResponse is called after each HTTP response is received.
	// method is the HTTP method, url is the full request URL, statusCode is
	// the HTTP status code, and body is the response body.
	LogResponse(method, url string, statusCode int, body []byte)
}

Logger is an interface for logging HTTP request and response details. Implement this interface and set it on ClientOptions to enable debug logging.

type Manufacturer

type Manufacturer struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// URL is the manufacturer's website
	URL string `json:"url,omitempty"`

	// SupportURL is the URL for getting support
	SupportURL string `json:"support_url,omitempty"`

	// SupportPhone is the phone number for getting support
	SupportPhone string `json:"support_phone,omitempty"`

	// SupportEmail is the email for getting support
	SupportEmail string `json:"support_email,omitempty"`

	// AssetsCount is the number of assets from this manufacturer
	AssetsCount int `json:"assets_count,omitempty"`
}

Manufacturer represents a Snipe-IT manufacturer. Manufacturers are companies that make the assets (e.g., "Apple", "Dell").

type Model

type Model struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// ModelNumber is the manufacturer's model identifier
	ModelNumber string `json:"model_number,omitempty"`

	// Category that this model belongs to
	Category Category `json:"category"`

	// Manufacturer of this model
	Manufacturer Manufacturer `json:"manufacturer"`

	// FieldsetID is the ID of the custom fieldset associated with this model
	FieldsetID int `json:"fieldset_id,omitempty"`

	// EOL is the End of Life in months for this model.
	// Uses FlexInt because the Snipe-IT API may return this as a string.
	EOL FlexInt `json:"eol,omitempty"`

	// AssetsCount is the number of assets of this model
	AssetsCount int `json:"assets_count,omitempty"`
}

Model represents a Snipe-IT model. Models define a specific type of asset (e.g., "MacBook Pro 16") and are associated with Categories and Manufacturers.

func (Model) MarshalJSON

func (m Model) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Model. The Snipe-IT API returns nested objects for Category and Manufacturer on GET, but expects flat ID fields (category_id, manufacturer_id) on POST/PUT.

type ModelResponse

type ModelResponse struct {
	Response
	Payload Model `json:"payload"`
}

ModelResponse represents the API response for a single model.

type ModelsResponse

type ModelsResponse struct {
	Response
	Rows []Model `json:"rows"`
}

ModelsResponse represents the API response for multiple models.

type ModelsService

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

ModelsService handles communication with the model-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/models

func (*ModelsService) Create

func (s *ModelsService) Create(model Model) (*ModelResponse, *http.Response, error)

Create creates a new model in Snipe-IT.

func (*ModelsService) CreateContext

func (s *ModelsService) CreateContext(ctx context.Context, model Model) (*ModelResponse, *http.Response, error)

CreateContext creates a new model in Snipe-IT with the provided context.

func (*ModelsService) Delete

func (s *ModelsService) Delete(id int) (*http.Response, error)

Delete deletes a model from Snipe-IT.

func (*ModelsService) DeleteContext

func (s *ModelsService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a model from Snipe-IT with the provided context.

func (*ModelsService) Get

func (s *ModelsService) Get(id int) (*ModelResponse, *http.Response, error)

Get fetches a single model by its ID.

func (*ModelsService) GetContext

func (s *ModelsService) GetContext(ctx context.Context, id int) (*ModelResponse, *http.Response, error)

GetContext fetches a single model by its ID with the provided context.

func (*ModelsService) List

List returns a list of models with pagination options.

func (*ModelsService) ListContext

func (s *ModelsService) ListContext(ctx context.Context, opts *ListOptions) (*ModelsResponse, *http.Response, error)

ListContext returns a list of models with the provided context and pagination options.

func (*ModelsService) Update

func (s *ModelsService) Update(id int, model Model) (*ModelResponse, *http.Response, error)

Update updates an existing model in Snipe-IT.

func (*ModelsService) UpdateContext

func (s *ModelsService) UpdateContext(ctx context.Context, id int, model Model) (*ModelResponse, *http.Response, error)

UpdateContext updates an existing model in Snipe-IT with the provided context.

type RateLimiter

type RateLimiter interface {
	// Wait blocks until a request can be made according to the rate limit.
	Wait(ctx context.Context) error
}

RateLimiter defines the interface for rate limiting API requests.

type RequestOptions

type RequestOptions struct {
	// Context is the context for the request.
	// If nil, context.Background() will be used.
	Context context.Context

	// DisableRetries, if true, disables automatic retries for this request,
	// regardless of the client's retry configuration.
	DisableRetries bool
}

RequestOptions contains options for individual API requests.

type Response

type Response struct {
	// Status of the API request, typically "success" or "error"
	Status string `json:"status"`

	// Message provided by the API, often used for error information.
	// Uses FlexMessage because the API returns this as either a plain string
	// or a JSON object with field-level validation errors.
	Message FlexMessage `json:"messages,omitempty"`

	// Payload contains the primary data for single-item responses
	Payload interface{} `json:"payload,omitempty"`

	// Total number of items available (for paginated responses)
	Total int `json:"total,omitempty"`

	// Count of items in the current response
	Count int `json:"count,omitempty"`

	// Rows contains the data for list/collection responses
	Rows interface{} `json:"rows,omitempty"`

	// Offset from the beginning of the collection (for pagination)
	Offset int `json:"offset,omitempty"`

	// Limit on the number of items returned (for pagination)
	Limit int `json:"limit,omitempty"`

	// PageSize indicates the number of items per page (for pagination)
	PageSize int `json:"pagesize,omitempty"`
}

Response represents a standard response structure from the Snipe-IT API. Different API endpoints may use different fields within this structure. For example, list endpoints typically use Total, Count, and Rows, while single-item endpoints typically use Payload.

type RetryPolicy

type RetryPolicy struct {
	// MaxRetries is the maximum number of times to retry a failed request.
	MaxRetries int

	// RetryableStatusCodes is a map of HTTP status codes that should trigger a retry.
	RetryableStatusCodes map[int]bool

	// InitialBackoff is the initial backoff duration before the first retry.
	InitialBackoff time.Duration

	// MaxBackoff is the maximum backoff duration between retries.
	MaxBackoff time.Duration

	// BackoffMultiplier is the factor by which the backoff increases after each retry.
	BackoffMultiplier float64

	// Jitter is a factor of randomness to add to the backoff to prevent clients
	// from retrying in lockstep. It's a value between 0 and 1, where 0 means no jitter
	// and 1 means the backoff can be anywhere from 0 to the calculated backoff time.
	Jitter float64
}

RetryPolicy defines how requests should be retried.

func DefaultRetryPolicy

func DefaultRetryPolicy() *RetryPolicy

DefaultRetryPolicy returns the default retry policy.

type SnipeTime

type SnipeTime struct {
	time.Time
}

SnipeTime represents a time field from the Snipe-IT API. Snipe-IT returns times as objects with "datetime" and "formatted" fields.

func (SnipeTime) MarshalJSON

func (st SnipeTime) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for SnipeTime.

func (*SnipeTime) UnmarshalJSON

func (st *SnipeTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for SnipeTime.

type StatusLabel

type StatusLabel struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// Type of status (typically "deployable", "undeployable" or "archived")
	Type string `json:"type"`

	// StatusMeta provides metadata about the status
	StatusMeta string `json:"status_meta"`

	// StatusType indicates the deployment status (typically same as Type)
	StatusType string `json:"status_type"`
}

StatusLabel represents a Snipe-IT status label. Status labels define the current state of an asset (e.g., "Ready to Deploy", "Deployed").

type StatusLabelResponse

type StatusLabelResponse struct {
	Response
	Payload StatusLabel `json:"payload"`
}

StatusLabelResponse represents the API response for a single status label.

type StatusLabelsResponse

type StatusLabelsResponse struct {
	Response
	Rows []StatusLabel `json:"rows"`
}

StatusLabelsResponse represents the API response for multiple status labels.

type StatusLabelsService

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

StatusLabelsService handles communication with the status label-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/statuslabels

func (*StatusLabelsService) Create

Create creates a new status label in Snipe-IT.

func (*StatusLabelsService) CreateContext

CreateContext creates a new status label in Snipe-IT with the provided context.

func (*StatusLabelsService) Delete

func (s *StatusLabelsService) Delete(id int) (*http.Response, error)

Delete deletes a status label from Snipe-IT.

func (*StatusLabelsService) DeleteContext

func (s *StatusLabelsService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a status label from Snipe-IT with the provided context.

func (*StatusLabelsService) Get

Get fetches a single status label by its ID.

func (*StatusLabelsService) GetContext

GetContext fetches a single status label by its ID with the provided context.

func (*StatusLabelsService) List

List returns a list of status labels with pagination options.

func (*StatusLabelsService) ListContext

ListContext returns a list of status labels with the provided context and pagination options.

func (*StatusLabelsService) Update

Update updates an existing status label in Snipe-IT.

func (*StatusLabelsService) UpdateContext

func (s *StatusLabelsService) UpdateContext(ctx context.Context, id int, label StatusLabel) (*StatusLabelResponse, *http.Response, error)

UpdateContext updates an existing status label in Snipe-IT with the provided context.

type Supplier

type Supplier struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// Address line 1
	Address string `json:"address,omitempty"`

	// Address line 2
	Address2 string `json:"address2,omitempty"`

	// City name
	City string `json:"city,omitempty"`

	// State or province
	State string `json:"state,omitempty"`

	// Country name
	Country string `json:"country,omitempty"`

	// Zip or postal code
	Zip string `json:"zip,omitempty"`

	// ContactName is the name of the primary contact at the supplier
	ContactName string `json:"contact,omitempty"`

	// Phone number of the supplier
	Phone string `json:"phone,omitempty"`

	// Fax number of the supplier
	Fax string `json:"fax,omitempty"`

	// Email address for the supplier
	Email string `json:"email,omitempty"`

	// URL is the supplier's website
	URL string `json:"url,omitempty"`

	// AssetsCount is the number of assets from this supplier
	AssetsCount int `json:"assets_count,omitempty"`
}

Supplier represents a Snipe-IT supplier. Suppliers are vendors or companies from whom assets are purchased.

type SupplierResponse

type SupplierResponse struct {
	Response
	Payload Supplier `json:"payload"`
}

SupplierResponse represents the API response for a single supplier.

type SuppliersResponse

type SuppliersResponse struct {
	Response
	Rows []Supplier `json:"rows"`
}

SuppliersResponse represents the API response for multiple suppliers.

type SuppliersService

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

SuppliersService handles communication with the supplier-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/suppliers

func (*SuppliersService) Create

func (s *SuppliersService) Create(supplier Supplier) (*SupplierResponse, *http.Response, error)

Create creates a new supplier in Snipe-IT.

func (*SuppliersService) CreateContext

func (s *SuppliersService) CreateContext(ctx context.Context, supplier Supplier) (*SupplierResponse, *http.Response, error)

CreateContext creates a new supplier in Snipe-IT with the provided context.

func (*SuppliersService) Delete

func (s *SuppliersService) Delete(id int) (*http.Response, error)

Delete deletes a supplier from Snipe-IT.

func (*SuppliersService) DeleteContext

func (s *SuppliersService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a supplier from Snipe-IT with the provided context.

func (*SuppliersService) Get

Get fetches a single supplier by its ID.

func (*SuppliersService) GetContext

func (s *SuppliersService) GetContext(ctx context.Context, id int) (*SupplierResponse, *http.Response, error)

GetContext fetches a single supplier by its ID with the provided context.

func (*SuppliersService) List

List returns a list of suppliers with pagination options.

func (*SuppliersService) ListContext

ListContext returns a list of suppliers with the provided context and pagination options.

func (*SuppliersService) Update

func (s *SuppliersService) Update(id int, supplier Supplier) (*SupplierResponse, *http.Response, error)

Update updates an existing supplier in Snipe-IT.

func (*SuppliersService) UpdateContext

func (s *SuppliersService) UpdateContext(ctx context.Context, id int, supplier Supplier) (*SupplierResponse, *http.Response, error)

UpdateContext updates an existing supplier in Snipe-IT with the provided context.

type TokenBucketRateLimiter

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

TokenBucketRateLimiter implements a simple token bucket rate limiter.

func NewTokenBucketRateLimiter

func NewTokenBucketRateLimiter(requestsPerSecond float64, burstSize int) *TokenBucketRateLimiter

NewTokenBucketRateLimiter creates a new token bucket rate limiter.

requestsPerSecond is the maximum number of requests allowed per second. burstSize is the maximum number of requests that can be made in a burst.

func (*TokenBucketRateLimiter) Wait

Wait blocks until a token is available or the context is canceled.

type User

type User struct {
	// CommonFields contains standard fields like ID, Name, etc.
	CommonFields

	// Username for logging into Snipe-IT
	Username string `json:"username"`

	// Email address of the user
	Email string `json:"email"`

	// FirstName of the user
	FirstName string `json:"first_name,omitempty"`

	// LastName of the user
	LastName string `json:"last_name,omitempty"`

	// Phone number of the user
	Phone string `json:"phone,omitempty"`

	// JobTitle of the user
	JobTitle string `json:"jobtitle,omitempty"`

	// Employee ID or number
	Employee string `json:"employee_num,omitempty"`

	// Activated indicates if the user account is active
	Activated bool `json:"activated"`
}

User represents a Snipe-IT user account. Users can check out assets and have assets assigned to them.

type UserResponse

type UserResponse struct {
	Response
	Payload User `json:"payload"`
}

UserResponse represents the API response for a single user.

type UsersResponse

type UsersResponse struct {
	Response
	Rows []User `json:"rows"`
}

UsersResponse represents the API response for multiple users.

type UsersService

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

UsersService handles communication with the user-related endpoints of the Snipe-IT API.

Snipe-IT API docs: https://snipe-it.readme.io/reference/users

func (*UsersService) Create

func (s *UsersService) Create(user User) (*UserResponse, *http.Response, error)

Create creates a new user in Snipe-IT.

func (*UsersService) CreateContext

func (s *UsersService) CreateContext(ctx context.Context, user User) (*UserResponse, *http.Response, error)

CreateContext creates a new user in Snipe-IT with the provided context.

func (*UsersService) Delete

func (s *UsersService) Delete(id int) (*http.Response, error)

Delete deletes a user from Snipe-IT.

func (*UsersService) DeleteContext

func (s *UsersService) DeleteContext(ctx context.Context, id int) (*http.Response, error)

DeleteContext deletes a user from Snipe-IT with the provided context.

func (*UsersService) Get

func (s *UsersService) Get(id int) (*UserResponse, *http.Response, error)

Get fetches a single user by their ID.

func (*UsersService) GetContext

func (s *UsersService) GetContext(ctx context.Context, id int) (*UserResponse, *http.Response, error)

GetContext fetches a single user by their ID with the provided context.

func (*UsersService) List

List returns a list of users with pagination options.

func (*UsersService) ListContext

func (s *UsersService) ListContext(ctx context.Context, opts *ListOptions) (*UsersResponse, *http.Response, error)

ListContext returns a list of users with the provided context and pagination options.

func (*UsersService) Update

func (s *UsersService) Update(id int, user User) (*UserResponse, *http.Response, error)

Update updates an existing user in Snipe-IT.

func (*UsersService) UpdateContext

func (s *UsersService) UpdateContext(ctx context.Context, id int, user User) (*UserResponse, *http.Response, error)

UpdateContext updates an existing user in Snipe-IT with the provided context.

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

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