Documentation
¶
Overview ¶
Package threecommon is the official Go client for the 3Common Public API.
Layout ¶
The package layout mirrors the Node SDK so behavior changes can be paired across languages:
- threecommon (this package) — Config, typed errors, helpers, version constants
- github.com/3-Common/sdk/sdk-go/client — recommended entry point: [client.New] returns a *client.API
- github.com/3-Common/sdk/sdk-go/resources/events — events resource (client + types)
- github.com/3-Common/sdk/sdk-go/resources/invoices — invoices resource (client + types)
- github.com/3-Common/sdk/sdk-go/resources/subscriptions — subscriptions resource (client + types)
- github.com/3-Common/sdk/sdk-go/filters — typed builder for the API's filters query parameter
- github.com/3-Common/sdk/sdk-go/pagination — generic Iter[T] used by every list endpoint
- github.com/3-Common/sdk/sdk-go/internal/core — HTTP transport machinery (not user-importable)
- github.com/3-Common/sdk/sdk-go/generated — oapi-codegen output from ../openapi/spec.yaml
File map of this package ¶
- config.go — Config, Logger, RetryDelay, DefaultRetryDelay
- errors_base.go — *APIError + Error() + Unwrap()
- errors_types.go — AuthError, PermissionError, NotFoundError, ValidationError, ConflictError, RateLimitError, ServerError, ConnectionError
- helpers.go — String / Int / Int64 / Bool / Float64 pointer helpers
- version.go — Version (the SDK package version)
- api_version.go — APIVersion + APIPath
Quick start ¶
Construct a client and call any resource method:
import (
"context"
"log"
"os"
threecommon "github.com/3-Common/sdk/sdk-go"
"github.com/3-Common/sdk/sdk-go/client"
"github.com/3-Common/sdk/sdk-go/resources/events"
)
api, err := client.New(threecommon.Config{APIKey: os.Getenv("THREECOMMON_API_KEY")})
if err != nil {
log.Fatal(err)
}
result, err := api.Events.List(context.Background(), &events.ListParams{
Status: events.StatusOpen,
PageSize: threecommon.Int(50),
})
Errors ¶
Every error returned by the SDK is or wraps a *APIError. Branch on the typed subtypes via errors.As:
var notFound *threecommon.NotFoundError
if errors.As(err, ¬Found) {
// 404 — notFound.RequestID, notFound.Code, etc.
}
Pagination ¶
Each list endpoint returns a single page plus an iterator for auto-pagination. The iterator type lives in github.com/3-Common/sdk/sdk-go/pagination:
iter := api.Events.ListAutoPaginate(ctx, nil)
for iter.Next() {
ev := iter.Current()
_ = ev
}
if err := iter.Err(); err != nil {
log.Fatal(err)
}
On Go 1.23+ the iterator also exposes a range-over-func variant:
for ev, err := range api.Events.ListAutoPaginate(ctx, nil).All() {
if err != nil {
log.Fatal(err)
}
_ = ev
}
Versioning ¶
The SDK follows SemVer. The pinned API version (sent as the Threecommon-Version header) is independent — the API can evolve without breaking already-deployed SDKs. Override it via Config.APIVersion.
Index ¶
- Constants
- Variables
- func Bool(v bool) *bool
- func Float64(v float64) *float64
- func Int(v int) *int
- func Int64(v int64) *int64
- func String(v string) *string
- type APIError
- type AuthError
- type Config
- type ConflictError
- type ConnectionError
- type Logger
- type NotFoundError
- type Nullable
- type PaymentRequiredError
- type PermissionError
- type RateLimitError
- type RetryDelay
- type ServerError
- type ValidationError
Constants ¶
const APIPath = "/v1"
APIPath is the path segment appended to Config.BaseURL when constructing request URLs. Pinned to /v1 for now; will become configurable when API v2 ships.
const APIVersion = "2026-04-29"
APIVersion is the version of the 3Common Public API this SDK is built against. Sent as the Threecommon-Version header on every request. The server uses it to dispatch to the matching version of its internal handlers, so older SDKs continue to receive the response shape they were compiled against even after the API evolves.
const Version = "0.13.0"
Version is the SDK package version, replaced by the release pipeline at publish time. Sent as part of the User-Agent and Threecommon-Client-Telemetry headers on every request.
Variables ¶
var DefaultRetryDelay = RetryDelay{ Initial: 500 * time.Millisecond, Max: 8 * time.Second, Jitter: true, }
DefaultRetryDelay is the schedule applied when Config.RetryDelay is the zero value: 500ms initial, 8s cap, jitter on.
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
// Code is a stable string matching the API's error.code field, e.g.
// "not_found" or "rate_limit_exceeded". For SDK-originated errors it
// describes the local condition (e.g. "missing_api_key").
Code string
// Message is human-readable. Safe to surface to end users.
Message string
// HTTPStatus is the response status, or 0 if the error originated before any response was received.
HTTPStatus int
// RequestID is the value of the X-Request-ID response header, when present. Useful for support correlation.
RequestID string
// Details is the parsed API error.details payload, when present.
Details map[string]any
// RawResponse is the raw response body, retained for debugging.
RawResponse string
// Cause is the underlying error for transport-level failures. Read it via [errors.Unwrap] or directly.
Cause error
}
APIError is the base type carried by every error the SDK returns from a request. The HTTP-status-specific subtypes (NotFoundError, AuthError, etc.) embed *APIError so its fields are accessible directly via field promotion. Branch on the subtype with errors.As:
var notFound *threecommon.NotFoundError
if errors.As(err, ¬Found) {
log.Println("missing:", notFound.RequestID)
}
Fields are populated best-effort: HTTPStatus is zero for connection errors, RequestID is empty when the server didn't return one, RawResponse is empty for non-text responses.
type AuthError ¶
type AuthError struct{ *APIError }
AuthError is returned for 401 Unauthorized — invalid, missing, or expired API key.
type Config ¶
type Config struct {
// APIKey authenticates every request. Required. Generate keys in the
// 3Common organizer dashboard (Settings -> API Keys). May also be supplied
// via the THREECOMMON_API_KEY environment variable.
APIKey string
// BaseURL is the API root. Defaults to https://api.3common.com.
BaseURL string
// APIVersion is sent as the Threecommon-Version header. Defaults to
// [APIVersion]. Override only if you need to opt into a newer server
// behavior than this SDK was built against.
APIVersion string
// Timeout is the per-request deadline applied via context. A zero value
// means 30s. To disable, pass a value larger than any expected request.
Timeout time.Duration
// MaxRetries is the number of retry attempts for idempotent requests on
// retryable failures (408, 425, 429, 5xx, network errors). nil uses the
// default of 3; pass [Int](0) to disable retries explicitly.
MaxRetries *int
// RetryDelay configures the exponential-backoff schedule. A zero value
// uses [DefaultRetryDelay].
RetryDelay RetryDelay
// HTTPClient overrides the underlying *http.Client. Useful for injecting
// a custom transport, proxy, or timeout. When nil, a fresh
// http.DefaultClient is used.
HTTPClient *http.Client
// Logger receives debug-level events. When nil, no logging occurs. The
// SDK never logs the API key or request/response bodies.
Logger Logger
// Telemetry, when non-nil, overrides the default opt-in behavior. Pass
// [Bool](false) to disable.
Telemetry *bool
}
Config controls how a github.com/3-Common/sdk/sdk-go/client.API talks to the 3Common API. Every field is optional except Config.APIKey. Zero values fall back to sensible defaults.
type ConflictError ¶
type ConflictError struct{ *APIError }
ConflictError is returned for 409 Conflict — the request conflicts with current resource state.
type ConnectionError ¶
type ConnectionError struct{ *APIError }
ConnectionError is returned when the request never completed: DNS failure, TCP reset, TLS error, context cancellation, etc. The original cause is available via errors.Unwrap.
type Logger ¶
Logger is an optional sink for SDK-internal debug events. The interface is minimal on purpose: any logger that exposes a key/value method (slog, logrus, zap, etc.) is trivial to adapt.
type NotFoundError ¶
type NotFoundError struct{ *APIError }
NotFoundError is returned for 404 Not Found.
type Nullable ¶ added in v0.8.0
type Nullable[T any] struct { // Value is the concrete value to send. Ignored when IsNull is true. Value T // IsNull, when true, serializes the field as JSON null. IsNull bool }
Nullable is an optional request field with three states: absent (a nil *Nullable, omitted from the request), an explicit JSON null (IsNull true, which the API reads as "clear this setting"), or a concrete Value.
Construct values with NullableOf and explicit nulls with Null:
api.Forms.UpdateElement(ctx, "frm_123", "elm_1", &forms.UpdateElementParams{
Placeholder: threecommon.NullableOf("Pick one..."),
HelperText: threecommon.Null[string](), // clear server-side
})
func Null ¶ added in v0.8.0
Null returns a Nullable that serializes as JSON null, which the API reads as "clear this setting".
func NullableOf ¶ added in v0.8.0
NullableOf returns a Nullable carrying the concrete value v.
func (Nullable[T]) MarshalJSON ¶ added in v0.8.0
MarshalJSON implements encoding/json.Marshaler.
func (*Nullable[T]) UnmarshalJSON ¶ added in v0.8.0
UnmarshalJSON implements encoding/json.Unmarshaler. Note that encoding/json decodes a JSON null into a nil *Nullable struct field without calling this method, so the null branch applies only when decoding into a Nullable that already exists.
type PaymentRequiredError ¶ added in v0.13.0
type PaymentRequiredError struct{ *APIError }
PaymentRequiredError is returned for 402 Payment Required — the request cannot proceed until a payment or billing prerequisite is satisfied (e.g. the host account is past due or lacks an active plan for the operation).
type PermissionError ¶
type PermissionError struct{ *APIError }
PermissionError is returned for 403 Forbidden — the API key lacks the scope required by the endpoint.
type RateLimitError ¶
RateLimitError is returned for 429 Too Many Requests. RetryAfter carries the parsed Retry-After header so callers can implement their own backoff; it is zero when the server did not provide one.
type RetryDelay ¶
RetryDelay configures the exponential-backoff schedule. Backoff doubles each attempt, capped at RetryDelay.Max. When RetryDelay.Jitter is true the SDK picks a random value in [0, capped].
type ServerError ¶
type ServerError struct{ *APIError }
ServerError is returned for 5xx — the API returned an unexpected server-side failure.
type ValidationError ¶
type ValidationError struct{ *APIError }
ValidationError is returned for 400 Bad Request and 422 Unprocessable Entity — request validation failed.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client is the recommended entry point for the SDK.
|
Package client is the recommended entry point for the SDK. |
|
examples
|
|
|
contacts/attach_payment_method
command
Run with: go run ./examples/contacts/attach_payment_method
|
Run with: go run ./examples/contacts/attach_payment_method |
|
contacts/auto_paginate
command
Run with: go run ./examples/contacts/auto_paginate
|
Run with: go run ./examples/contacts/auto_paginate |
|
contacts/bulk_upsert
command
Run with: go run ./examples/contacts/bulk_upsert
|
Run with: go run ./examples/contacts/bulk_upsert |
|
contacts/count
command
Run with: go run ./examples/contacts/count
|
Run with: go run ./examples/contacts/count |
|
contacts/create
command
Run with: go run ./examples/contacts/create
|
Run with: go run ./examples/contacts/create |
|
contacts/create_payment_method_setup_intent
command
Run with: go run ./examples/contacts/create_payment_method_setup_intent
|
Run with: go run ./examples/contacts/create_payment_method_setup_intent |
|
contacts/delete
command
Run with: go run ./examples/contacts/delete
|
Run with: go run ./examples/contacts/delete |
|
contacts/error_handling
command
Run with: go run ./examples/contacts/error_handling
|
Run with: go run ./examples/contacts/error_handling |
|
contacts/filters
command
Run with: go run ./examples/contacts/filters
|
Run with: go run ./examples/contacts/filters |
|
contacts/list
command
Run with: go run ./examples/contacts/list
|
Run with: go run ./examples/contacts/list |
|
contacts/list_activity
command
Run with: go run ./examples/contacts/list_activity
|
Run with: go run ./examples/contacts/list_activity |
|
contacts/remove_payment_method
command
Run with: go run ./examples/contacts/remove_payment_method
|
Run with: go run ./examples/contacts/remove_payment_method |
|
contacts/retrieve
command
Run with: go run ./examples/contacts/retrieve
|
Run with: go run ./examples/contacts/retrieve |
|
contacts/retrieve_payment_method
command
Run with: go run ./examples/contacts/retrieve_payment_method
|
Run with: go run ./examples/contacts/retrieve_payment_method |
|
contacts/update
command
Run with: go run ./examples/contacts/update
|
Run with: go run ./examples/contacts/update |
|
entitlements/auto_paginate
command
Run with: go run ./examples/entitlements/auto_paginate
|
Run with: go run ./examples/entitlements/auto_paginate |
|
entitlements/consume
command
Run with: go run ./examples/entitlements/consume
|
Run with: go run ./examples/entitlements/consume |
|
entitlements/error_handling
command
Run with: go run ./examples/entitlements/error_handling
|
Run with: go run ./examples/entitlements/error_handling |
|
entitlements/grant
command
Run with: go run ./examples/entitlements/grant
|
Run with: go run ./examples/entitlements/grant |
|
entitlements/list
command
Run with: go run ./examples/entitlements/list
|
Run with: go run ./examples/entitlements/list |
|
entitlements/lookup
command
Run with: go run ./examples/entitlements/lookup
|
Run with: go run ./examples/entitlements/lookup |
|
entitlements/retrieve
command
Run with: go run ./examples/entitlements/retrieve
|
Run with: go run ./examples/entitlements/retrieve |
|
events/auto_paginate
command
Run with: go run ./examples/events/auto_paginate
|
Run with: go run ./examples/events/auto_paginate |
|
events/error_handling
command
Run with: go run ./examples/events/error_handling
|
Run with: go run ./examples/events/error_handling |
|
events/filters
command
Run with: go run ./examples/events/filters
|
Run with: go run ./examples/events/filters |
|
events/list
command
Run with: go run ./examples/events/list
|
Run with: go run ./examples/events/list |
|
events/retrieve
command
Run with: go run ./examples/events/retrieve
|
Run with: go run ./examples/events/retrieve |
|
events/update
command
Run with: go run ./examples/events/update
|
Run with: go run ./examples/events/update |
|
features/archive
command
Run with: go run ./examples/features/archive
|
Run with: go run ./examples/features/archive |
|
features/auto_paginate
command
Run with: go run ./examples/features/auto_paginate
|
Run with: go run ./examples/features/auto_paginate |
|
features/create
command
Run with: go run ./examples/features/create
|
Run with: go run ./examples/features/create |
|
features/error_handling
command
Run with: go run ./examples/features/error_handling
|
Run with: go run ./examples/features/error_handling |
|
features/list
command
Run with: go run ./examples/features/list
|
Run with: go run ./examples/features/list |
|
features/resolve
command
Run with: go run ./examples/features/resolve
|
Run with: go run ./examples/features/resolve |
|
features/retrieve
command
Run with: go run ./examples/features/retrieve
|
Run with: go run ./examples/features/retrieve |
|
features/unarchive
command
Run with: go run ./examples/features/unarchive
|
Run with: go run ./examples/features/unarchive |
|
features/update
command
Run with: go run ./examples/features/update
|
Run with: go run ./examples/features/update |
|
forms/add_element
command
Run with: go run ./examples/forms/add_element
|
Run with: go run ./examples/forms/add_element |
|
forms/add_logic_rule
command
Run with: go run ./examples/forms/add_logic_rule
|
Run with: go run ./examples/forms/add_logic_rule |
|
forms/auto_paginate
command
Run with: go run ./examples/forms/auto_paginate
|
Run with: go run ./examples/forms/auto_paginate |
|
forms/create
command
Run with: go run ./examples/forms/create
|
Run with: go run ./examples/forms/create |
|
forms/delete_element
command
Run with: go run ./examples/forms/delete_element
|
Run with: go run ./examples/forms/delete_element |
|
forms/disable_other_option
command
Run with: go run ./examples/forms/disable_other_option
|
Run with: go run ./examples/forms/disable_other_option |
|
forms/duplicate
command
Run with: go run ./examples/forms/duplicate
|
Run with: go run ./examples/forms/duplicate |
|
forms/enable_other_option
command
Run with: go run ./examples/forms/enable_other_option
|
Run with: go run ./examples/forms/enable_other_option |
|
forms/error_handling
command
Run with: go run ./examples/forms/error_handling
|
Run with: go run ./examples/forms/error_handling |
|
forms/list
command
Run with: go run ./examples/forms/list
|
Run with: go run ./examples/forms/list |
|
forms/move_element
command
Run with: go run ./examples/forms/move_element
|
Run with: go run ./examples/forms/move_element |
|
forms/remove_logic_rule
command
Run with: go run ./examples/forms/remove_logic_rule
|
Run with: go run ./examples/forms/remove_logic_rule |
|
forms/retrieve
command
Run with: go run ./examples/forms/retrieve
|
Run with: go run ./examples/forms/retrieve |
|
forms/update
command
Run with: go run ./examples/forms/update
|
Run with: go run ./examples/forms/update |
|
forms/update_element
command
Run with: go run ./examples/forms/update_element
|
Run with: go run ./examples/forms/update_element |
|
invoices/auto_charge
command
Run with: go run ./examples/invoices/auto_charge
|
Run with: go run ./examples/invoices/auto_charge |
|
invoices/auto_paginate
command
Run with: go run ./examples/invoices/auto_paginate
|
Run with: go run ./examples/invoices/auto_paginate |
|
invoices/create
command
Run with: go run ./examples/invoices/create
|
Run with: go run ./examples/invoices/create |
|
invoices/delete_draft
command
Run with: go run ./examples/invoices/delete_draft
|
Run with: go run ./examples/invoices/delete_draft |
|
invoices/error_handling
command
Run with: go run ./examples/invoices/error_handling
|
Run with: go run ./examples/invoices/error_handling |
|
invoices/list
command
Run with: go run ./examples/invoices/list
|
Run with: go run ./examples/invoices/list |
|
invoices/record_payment
command
Run with: go run ./examples/invoices/record_payment
|
Run with: go run ./examples/invoices/record_payment |
|
invoices/refund_payment
command
Run with: go run ./examples/invoices/refund_payment
|
Run with: go run ./examples/invoices/refund_payment |
|
invoices/retrieve
command
Run with: go run ./examples/invoices/retrieve
|
Run with: go run ./examples/invoices/retrieve |
|
invoices/send
command
Run with: go run ./examples/invoices/send
|
Run with: go run ./examples/invoices/send |
|
invoices/update
command
Run with: go run ./examples/invoices/update
|
Run with: go run ./examples/invoices/update |
|
invoices/void
command
Run with: go run ./examples/invoices/void
|
Run with: go run ./examples/invoices/void |
|
prices/archive
command
Run with: go run ./examples/prices/archive
|
Run with: go run ./examples/prices/archive |
|
prices/auto_paginate
command
Run with: go run ./examples/prices/auto_paginate
|
Run with: go run ./examples/prices/auto_paginate |
|
prices/create
command
Run with: go run ./examples/prices/create
|
Run with: go run ./examples/prices/create |
|
prices/error_handling
command
Run with: go run ./examples/prices/error_handling
|
Run with: go run ./examples/prices/error_handling |
|
prices/list
command
Run with: go run ./examples/prices/list
|
Run with: go run ./examples/prices/list |
|
prices/retrieve
command
Run with: go run ./examples/prices/retrieve
|
Run with: go run ./examples/prices/retrieve |
|
prices/unarchive
command
Run with: go run ./examples/prices/unarchive
|
Run with: go run ./examples/prices/unarchive |
|
prices/update
command
Run with: go run ./examples/prices/update
|
Run with: go run ./examples/prices/update |
|
properties/auto_paginate
command
Run with: go run ./examples/properties/auto_paginate
|
Run with: go run ./examples/properties/auto_paginate |
|
properties/create
command
Run with: go run ./examples/properties/create
|
Run with: go run ./examples/properties/create |
|
properties/error_handling
command
Run with: go run ./examples/properties/error_handling
|
Run with: go run ./examples/properties/error_handling |
|
properties/list
command
Run with: go run ./examples/properties/list
|
Run with: go run ./examples/properties/list |
|
properties/retrieve
command
Run with: go run ./examples/properties/retrieve
|
Run with: go run ./examples/properties/retrieve |
|
properties/update
command
Run with: go run ./examples/properties/update
|
Run with: go run ./examples/properties/update |
|
subscriptions/auto_paginate
command
Run with: go run ./examples/subscriptions/auto_paginate
|
Run with: go run ./examples/subscriptions/auto_paginate |
|
subscriptions/cancel
command
Run with: go run ./examples/subscriptions/cancel
|
Run with: go run ./examples/subscriptions/cancel |
|
subscriptions/comp_next_cycle
command
Run with: go run ./examples/subscriptions/comp_next_cycle
|
Run with: go run ./examples/subscriptions/comp_next_cycle |
|
subscriptions/create
command
Run with: go run ./examples/subscriptions/create
|
Run with: go run ./examples/subscriptions/create |
|
subscriptions/list
command
Run with: go run ./examples/subscriptions/list
|
Run with: go run ./examples/subscriptions/list |
|
subscriptions/manage_url
command
Run with: go run ./examples/subscriptions/manage_url
|
Run with: go run ./examples/subscriptions/manage_url |
|
subscriptions/preview_upcoming_invoice
command
Run with: go run ./examples/subscriptions/preview_upcoming_invoice
|
Run with: go run ./examples/subscriptions/preview_upcoming_invoice |
|
subscriptions/retrieve
command
Run with: go run ./examples/subscriptions/retrieve
|
Run with: go run ./examples/subscriptions/retrieve |
|
subscriptions/uncomp_next_cycle
command
Run with: go run ./examples/subscriptions/uncomp_next_cycle
|
Run with: go run ./examples/subscriptions/uncomp_next_cycle |
|
subscriptions/update
command
Run with: go run ./examples/subscriptions/update
|
Run with: go run ./examples/subscriptions/update |
|
Package filters provides the typed builder and wire types for the API's `filters` query parameter.
|
Package filters provides the typed builder and wire types for the API's `filters` query parameter. |
|
Package generated provides primitives to interact with the openapi HTTP API.
|
Package generated provides primitives to interact with the openapi HTTP API. |
|
internal
|
|
|
core
Package core implements the HTTP machinery shared by every resource package.
|
Package core implements the HTTP machinery shared by every resource package. |
|
Package pagination contains the generic auto-paginating iterator returned by every list endpoint's auto-paginate variant.
|
Package pagination contains the generic auto-paginating iterator returned by every list endpoint's auto-paginate variant. |
|
resources
|
|
|
contacts
Package contacts provides the contacts resource client for the 3Common API.
|
Package contacts provides the contacts resource client for the 3Common API. |
|
entitlements
Package entitlements provides the entitlements resource client for the 3Common API.
|
Package entitlements provides the entitlements resource client for the 3Common API. |
|
events
Package events provides the events resource client for the 3Common API.
|
Package events provides the events resource client for the 3Common API. |
|
features
Package features provides the features resource client for the 3Common API.
|
Package features provides the features resource client for the 3Common API. |
|
forms
Package forms provides the forms resource client for the 3Common API.
|
Package forms provides the forms resource client for the 3Common API. |
|
invoices
Package invoices provides the invoices resource client for the 3Common API.
|
Package invoices provides the invoices resource client for the 3Common API. |
|
prices
Package prices provides the prices resource client for the 3Common API.
|
Package prices provides the prices resource client for the 3Common API. |
|
properties
Package properties provides the properties resource client for the 3Common API.
|
Package properties provides the properties resource client for the 3Common API. |
|
subscriptions
Package subscriptions provides the subscriptions resource client for the 3Common API.
|
Package subscriptions provides the subscriptions resource client for the 3Common API. |
|
scripts
|
|
|
livesmoke
command
Pre-release smoke test against the live API.
|
Pre-release smoke test against the live API. |