Documentation
¶
Overview ¶
Package instantly is the foundation of the Instantly.ai V2 API SDK.
It provides the Client — an authenticated, immutable connection to the API — along with the low-level request plumbing (Do, Get, Post, Patch, Put, Delete, DoRaw), the shared query builder (Query), the generic pagination helper (Iterate), typed API errors (APIError), and cross-resource enums.
Typed access to each API resource lives in its own subpackage — for example github.com/mrz1836/go-instantly/email — so importing one resource pulls in only that resource plus this foundation and the standard library, never the test-support code or the other resources.
Construct a client once and hand it to a resource service:
client := instantly.NewClient("[API-KEY]")
svc := email.New(client)
page, err := svc.List(ctx, email.WithLimit(50))
Index ¶
- Constants
- func BuildPath(base string, values url.Values) string
- func DeleteResult[T any](ctx context.Context, c *Client, path string) (*T, error)
- func GetResult[T any](ctx context.Context, c *Client, path string) (*T, error)
- func Iterate[T any](ctx context.Context, fetch FetchPage[T]) iter.Seq2[*T, error]
- func JoinPath(base string, segments ...string) string
- func Paginate[T any, O ~func(*Query)](ctx context.Context, opts []O, withCursor func(string) O, ...) iter.Seq2[*T, error]
- func PatchResult[T any](ctx context.Context, c *Client, path string, payload any) (*T, error)
- func PostResult[T any](ctx context.Context, c *Client, path string, payload any) (*T, error)
- func Ptr[T any](v T) *T
- type APIError
- type Client
- func (c *Client) Delete(ctx context.Context, path string, out any) error
- func (c *Client) Do(ctx context.Context, method, path string, payload, out any) error
- func (c *Client) DoRaw(ctx context.Context, method, path string, payload any) ([]byte, error)
- func (c *Client) Get(ctx context.Context, path string, out any) error
- func (c *Client) Patch(ctx context.Context, path string, payload, out any) error
- func (c *Client) Post(ctx context.Context, path string, payload, out any) error
- func (c *Client) Put(ctx context.Context, path string, payload, out any) error
- type ClientOption
- type CountResponse
- type FetchPage
- type Page
- type Query
- func (q *Query) AddString(key, value string) *Query
- func (q *Query) Encode() string
- func (q *Query) Get(key string) string
- func (q *Query) Len() int
- func (q *Query) Path(base string) string
- func (q *Query) SetBool(key string, value bool) *Query
- func (q *Query) SetInt(key string, value int) *Query
- func (q *Query) SetString(key, value string) *Query
- type SortOrder
Examples ¶
Constants ¶
const ( // ErrCodeAccountAuthError indicates the sending account failed to authenticate. ErrCodeAccountAuthError = "ACC_AUTH_ERROR" // ErrCodeAccountNotFound indicates the requested sending account does not exist. ErrCodeAccountNotFound = "ACC_NOT_FOUND" // ErrCodeAccountUnknownError indicates an unclassified sending account failure. ErrCodeAccountUnknownError = "ACC_UNKNOWN_ERROR" )
Error codes the API delivers inside an HTTP 200 response body.
Variables ¶
This section is empty.
Functions ¶
func BuildPath ¶
BuildPath appends encoded query parameters to a path, returning the bare path when there are none.
func DeleteResult ¶ added in v0.2.0
DeleteResult performs a DELETE and decodes the response into a fresh T. It returns a nil *T on any error.
func GetResult ¶ added in v0.2.0
GetResult performs a GET and decodes the response into a fresh T.
It collapses the out := &T{}; if err := client.Get(...); return out, nil block every read method used to repeat. On any error it returns a nil *T, so a failed decode never hands back a partly populated value.
func Iterate ¶
Iterate turns a paginated fetch into a range-over-func sequence, following the cursor until the API stops returning one.
It centralizes every termination guard so each resource's ListIter is a thin closure over its own List call:
- the context is checked before every page, so a cancellation between pages stops iteration instead of issuing another request;
- the first error is yielded once with a nil *T and ends iteration;
- an empty page ends iteration even if the API keeps returning a cursor, which bounds the total number of requests;
- iteration stops once the next cursor comes back empty.
Iteration also stops as soon as the consumer breaks out of the range loop, so no page is fetched that the consumer never reads.
func JoinPath ¶ added in v0.2.0
JoinPath escapes each segment and joins it onto base with a slash.
It replaces the hand-built base + "/" + url.PathEscape(id) joins, escaping every segment so an id carrying a slash, space, or other reserved character cannot alter the request path. With no segments it returns base unchanged.
func Paginate ¶ added in v0.2.0
func Paginate[T any, O ~func(*Query)]( ctx context.Context, opts []O, withCursor func(string) O, list func(ctx context.Context, opts ...O) (*Page[T], error), ) iter.Seq2[*T, error]
Paginate turns a resource's List method into a range-over-func sequence, carrying the caller's options onto every page and overriding the pagination cursor with each page's next_starting_after.
It collapses the near-identical ListIter closures the GET-with-options resources used to carry: pass the caller's options, the option constructor that sets the cursor (WithStartingAfter), and the List method itself. The caller's option slice is never mutated. All the termination guards live in Iterate, which this delegates to.
func PatchResult ¶ added in v0.2.0
PatchResult performs a PATCH with payload and decodes the response into a fresh T. It returns a nil *T on any error.
func PostResult ¶ added in v0.2.0
PostResult performs a POST with payload and decodes the response into a fresh T. It returns a nil *T on any error.
Types ¶
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status code of the response. It is 200 when the
// error arrived inside an otherwise successful response.
StatusCode int64 `json:"statusCode,omitempty"`
// Code is the machine-readable error code, such as ACC_AUTH_ERROR for an
// error delivered at HTTP 200, or Unauthorized for a 4xx envelope.
Code string `json:"error,omitempty"`
// Message is the human-readable error detail, when the API provides one.
Message string `json:"message,omitempty"`
}
APIError represents an error returned by the Instantly.ai API.
It covers both wire shapes the API uses: a 4xx envelope carrying {statusCode, error, message}, and an error code delivered inside an HTTP 200 body as {"error": "ACC_AUTH_ERROR"}. Both are returned as an error, so err != nil catches every real failure.
Callers can inspect the code with errors.As:
var apiErr *instantly.APIError
if errors.As(err, &apiErr) && apiErr.Code == instantly.ErrCodeAccountAuthError {
// the sending account failed to authenticate
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a connection to the Instantly.ai V2 API.
Every request is authenticated with a single V2 API key sent as a bearer token. V2 keys are distinct from V1 keys and are not interchangeable.
A Client is safe for concurrent use by multiple goroutines. It is immutable after construction: configure it once with the functional options passed to NewClient rather than mutating it afterwards.
The low-level request plumbing (Do, Get, Post, Patch, Put, Delete, DoRaw) is exported so the resource subpackages — which live in their own packages — can build on it, and so consumers keep a forward-compatible escape hatch for any endpoint the typed resource packages do not yet wrap.
See https://developer.instantly.ai/getting-started/authorization
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient builds a Client from the provided Instantly V2 API key.
Without options it uses a default HTTP client and the default API base URL. Pass functional options such as WithHTTPClient or WithBaseURL to customize it.
Example ¶
ExampleNewClient constructs a client once and hands it to a resource service.
package main
import (
"fmt"
"github.com/mrz1836/go-instantly"
"github.com/mrz1836/go-instantly/email"
)
func main() {
client := instantly.NewClient("my-v2-api-key",
instantly.WithUserAgent("my-app/1.0"),
)
svc := email.New(client)
_ = svc
fmt.Println("email service ready")
}
Output: email service ready
func (*Client) Delete ¶
Delete performs a DELETE request and decodes the response into out.
Endpoints that delete with a request body are rare; call Do with http.MethodDelete and a payload directly for those.
func (*Client) Do ¶
Do performs an API request and decodes the response into out.
It is the single choke point every resource method routes through: it marshals the payload, authenticates the request, and converts both API error wire shapes into a returned error before out is ever populated. A nil payload sends no body, and a nil out skips response decoding.
func (*Client) DoRaw ¶
DoRaw performs an API request and returns the raw response body.
It runs the same error handling as Do — a failing status or an error embedded in a success body is returned as an error — but hands back the undecoded bytes for endpoints that answer with a non-JSON payload, such as a CSV export.
func (*Client) Patch ¶
Patch performs a PATCH request with the given payload and decodes the response into out.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client during construction.
Options are applied in order, so a later option overrides an earlier one that sets the same field.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL overrides the root API endpoint, chiefly to point the client at a mock server in tests. An empty value falls back to the default base URL.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets the HTTP client used to execute requests, which is how a caller supplies a custom transport, proxy, or timeout.
func WithHTTPHeader ¶
func WithHTTPHeader(key, value string) ClientOption
WithHTTPHeader adds an extra header sent on every request.
The header is merged onto each request before the mandatory Accept, Content-Type, and Authorization headers, so it cannot override them. Calling it more than once with the same key adds multiple values for that header.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent sets the User-Agent header sent on every request.
type CountResponse ¶ added in v0.2.0
type CountResponse struct {
// Count is the counted value the endpoint reported.
Count int64 `json:"count"`
}
CountResponse is the {"count":N} wrapper the counting endpoints return.
It is the single decode target the launched-campaign, unread-email, and bulk-delete counts share, in place of a per-resource clone.
type FetchPage ¶
FetchPage fetches a single page of a cursor-paginated list.
It returns the items on the page, the cursor for the following page (empty on the last page), and any error. The cursor passed in is empty on the first call and is the previous page's next cursor thereafter.
type Page ¶ added in v0.2.0
type Page[T any] struct { // Items are the resources on this page. Items []T `json:"items"` // NextStartingAfter is the cursor for the following page, and is empty on // the last page. NextStartingAfter string `json:"next_starting_after,omitempty"` }
Page is one page of a cursor-paginated list, shared by every resource.
Each resource package aliases its ListResponse to a Page of its own item type (type ListResponse = instantly.Page[Campaign]). Because the alias is an identical type rather than a distinct defined one, the generic helpers below — Paginate in particular — accept a resource's List method directly.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query accumulates the query parameters a list request sends.
Resource packages expose their own typed ListOption values that write into a Query, which keeps every query key and value compile-time checked while sharing a single accumulator and encoder across all 28 resources. Setting the same key twice keeps the last value.
func ApplyOptions ¶ added in v0.2.0
ApplyOptions builds a Query from the supplied typed per-resource options.
Every resource defines its own ListOption as func(*Query); the ~func(*Query) constraint accepts any of them, so this single helper replaces the identical apply loop each List method used to carry. A nil option is skipped rather than invoked.
func NewQuery ¶
func NewQuery() *Query
NewQuery returns an empty Query ready for options to write into.
func SetEnum ¶
SetEnum sets a string-backed enum query parameter.
It is a free function rather than a method because Go methods cannot take type parameters; resource options call it as instantly.SetEnum(q, key, value).
func (*Query) AddString ¶
AddString appends a string value to a query parameter, keeping any values already set. It is how a repeated array parameter (key=a&key=b) is built.
func (*Query) Get ¶
Get returns the first value set for key, or the empty string when key is unset. It is chiefly a testing convenience for asserting what an option wrote.
func (*Query) Len ¶
Len reports how many distinct query parameters have been set. Tests use it as a completeness guard, asserting an option renders exactly one parameter.
func (*Query) Path ¶
Path appends the encoded parameters to base, returning the bare base when no parameter has been set so an unfiltered request never carries an empty "?".
Directories
¶
| Path | Synopsis |
|---|---|
|
Package account provides typed access to the Instantly.ai V2 Account API.
|
Package account provides typed access to the Instantly.ai V2 Account API. |
|
Package accountcampaign provides typed access to the Instantly.ai V2 account-campaign-mappings endpoint: the campaigns a sending account belongs to.
|
Package accountcampaign provides typed access to the Instantly.ai V2 account-campaign-mappings endpoint: the campaigns a sending account belongs to. |
|
Package apikey provides typed access to the Instantly.ai V2 API Key API.
|
Package apikey provides typed access to the Instantly.ai V2 API Key API. |
|
Package auditlog provides typed access to the Instantly.ai V2 Audit Log API.
|
Package auditlog provides typed access to the Instantly.ai V2 Audit Log API. |
|
Package backgroundjob provides typed access to the Instantly.ai V2 Background Job API.
|
Package backgroundjob provides typed access to the Instantly.ai V2 Background Job API. |
|
Package blocklist provides typed access to the Instantly.ai V2 Block List Entry API.
|
Package blocklist provides typed access to the Instantly.ai V2 Block List Entry API. |
|
Package campaign provides typed access to the Instantly.ai V2 Campaign API.
|
Package campaign provides typed access to the Instantly.ai V2 Campaign API. |
|
Package crm provides typed access to the Instantly.ai V2 CRM Actions API.
|
Package crm provides typed access to the Instantly.ai V2 CRM Actions API. |
|
Package customtag provides typed access to the Instantly.ai V2 Custom Tag API.
|
Package customtag provides typed access to the Instantly.ai V2 Custom Tag API. |
|
Package customtagmapping provides typed access to the Instantly.ai V2 Custom Tag Mapping API.
|
Package customtagmapping provides typed access to the Instantly.ai V2 Custom Tag Mapping API. |
|
Package dfy provides typed access to the Instantly.ai V2 Done-For-You (DFY) Email Account Order API.
|
Package dfy provides typed access to the Instantly.ai V2 Done-For-You (DFY) Email Account Order API. |
|
Package email provides typed access to the Instantly.ai V2 Email API.
|
Package email provides typed access to the Instantly.ai V2 Email API. |
|
Package emailverification provides typed access to the Instantly.ai V2 Email Verification API.
|
Package emailverification provides typed access to the Instantly.ai V2 Email Verification API. |
|
Package main is an example of how to use the Instantly.ai V2 Go SDK.
|
Package main is an example of how to use the Instantly.ai V2 Go SDK. |
|
Package inboxanalytics provides typed access to the Instantly.ai V2 Inbox Placement Analytics API.
|
Package inboxanalytics provides typed access to the Instantly.ai V2 Inbox Placement Analytics API. |
|
Package inboxreport provides typed access to the Instantly.ai V2 Inbox Placement blacklist and SpamAssassin report API.
|
Package inboxreport provides typed access to the Instantly.ai V2 Inbox Placement blacklist and SpamAssassin report API. |
|
Package inboxtest provides typed access to the Instantly.ai V2 Inbox Placement Test API.
|
Package inboxtest provides typed access to the Instantly.ai V2 Inbox Placement Test API. |
|
internal
|
|
|
instantlytest
Package instantlytest provides the shared test harness for the go-instantly SDK: a small HTTP mock router, a reusable testify suite, and assertion helpers.
|
Package instantlytest provides the shared test harness for the go-instantly SDK: a small HTTP mock router, a reusable testify suite, and assertion helpers. |
|
Package lead provides typed access to the Instantly.ai V2 Lead API.
|
Package lead provides typed access to the Instantly.ai V2 Lead API. |
|
Package leadlabel provides typed access to the Instantly.ai V2 Lead Label API.
|
Package leadlabel provides typed access to the Instantly.ai V2 Lead Label API. |
|
Package leadlist provides typed access to the Instantly.ai V2 Lead List API.
|
Package leadlist provides typed access to the Instantly.ai V2 Lead List API. |
|
Package oauth provides typed access to the Instantly.ai V2 OAuth API.
|
Package oauth provides typed access to the Instantly.ai V2 OAuth API. |
|
Package subsequence provides typed access to the Instantly.ai V2 Campaign Subsequence API.
|
Package subsequence provides typed access to the Instantly.ai V2 Campaign Subsequence API. |
|
Package supersearch provides typed access to the Instantly.ai V2 SuperSearch Enrichment API.
|
Package supersearch provides typed access to the Instantly.ai V2 SuperSearch Enrichment API. |
|
Package webhook provides typed access to the Instantly.ai V2 Webhook API.
|
Package webhook provides typed access to the Instantly.ai V2 Webhook API. |
|
Package webhookevent provides typed access to the Instantly.ai V2 Webhook Event API.
|
Package webhookevent provides typed access to the Instantly.ai V2 Webhook Event API. |
|
Package workspace provides typed access to the Instantly.ai V2 Workspace API.
|
Package workspace provides typed access to the Instantly.ai V2 Workspace API. |
|
Package workspacebilling provides typed access to the Instantly.ai V2 Workspace Billing API.
|
Package workspacebilling provides typed access to the Instantly.ai V2 Workspace Billing API. |
|
Package workspacegroup provides typed access to the Instantly.ai V2 Workspace Group Member API.
|
Package workspacegroup provides typed access to the Instantly.ai V2 Workspace Group Member API. |
|
Package workspacemember provides typed access to the Instantly.ai V2 Workspace Member API.
|
Package workspacemember provides typed access to the Instantly.ai V2 Workspace Member API. |
