This directory documents the public API of the Apify Go client, organized by resource. Each page lists the available methods with their parameters and short, runnable snippets. For an overview, configuration, error handling, and the full resource table, see the top-level README.
All snippets assume a configured client and a context:
client := apify.NewClient(apify.WithToken("my-api-token"))
ctx := context.Background()NewClient takes functional options; authentication is supplied via apify.WithToken. It
does not read APIFY_TOKEN (or any other environment variable) automatically. Read it
yourself if you want that, e.g. apify.NewClient(apify.WithToken(os.Getenv("APIFY_TOKEN"))).
Pass additional options for non-default settings (base URL, retries, timeout, user-agent
suffix, custom HTTP backend).
WithToken is optional. Omit it to create an unauthenticated client that can still call the
few endpoints that require no token. For example, resolving and fetching a public Actor's
default build needs only the public Actor ID (no build ID and no token):
publicClient := apify.NewClient()
buildClient, err := publicClient.Actor("apify/hello-world").DefaultBuild(ctx, nil)
if err != nil {
log.Fatal(err)
}
build, ok, err := buildClient.Get(ctx)A runnable version is in examples/public_build_no_token.
Account-scoped endpoints and anything that reads or writes your resources require a token.
Methods that fetch a single resource return a (value, ok, error) triple: a missing
resource is reported by ok == false rather than an error. API failures are returned as
*apify.APIError (see error handling).
Optional option-struct fields are pointer-typed (so "unset" is distinguishable from a zero
value). The exported generic helper apify.Ptr[T](v T) *T sets them inline without a named
local:
page, err := client.Actors().List(ctx, apify.ActorListOptions{
My: apify.Ptr(true),
Limit: apify.Ptr(int64(10)),
})Most List methods (builds, runs, tasks, schedules, webhooks, Actor versions) take the shared
apify.ListOptions, which carries the standard pagination/ordering controls. All fields are
optional pointers; leave a field nil to use the API default. Use apify.Ptr to set them
inline.
| Field | Type | Meaning |
|---|---|---|
Offset |
*int64 |
Number of items to skip from the start of the list. |
Limit |
*int64 |
Maximum number of items to return. |
Desc |
*bool |
If true, return items newest-first. |
page, err := client.Builds().List(ctx, apify.ListOptions{
Limit: apify.Ptr(int64(50)),
Desc: apify.Ptr(true),
})Collections with extra filters use a dedicated options type instead of (or in addition to)
ListOptions: ActorListOptions (Actors), StorageListOptions (datasets/key-value
stores/request queues), StoreListOptions (the Store), and RunListOptions (runs, passed
alongside ListOptions). Each is documented on its resource page.
List/iterate methods return apify.PaginationList[T], one page plus the API's pagination
metadata:
| Field | Type | Meaning |
|---|---|---|
Items |
[]T |
The items in this page. |
Total |
int64 |
Total items available across all pages. |
Count |
int64 |
Number of items actually returned in this page. |
Offset |
int64 |
Items skipped before this page. |
Limit |
int64 |
Max items the API would return for this request. |
Desc |
bool |
Whether items are in descending order. |
Totalcan lag right after a write. The API computes the count asynchronously, so immediately after aPushItems(or other write)Totalmay not yet include the new items. Re-read after a short delay if you need an exact post-write total.
The collection List methods (Actors, builds, runs, tasks, schedules, webhooks, datasets,
key-value stores, request queues) return PaginationList[T]. The within-storage listers use
their own page/head containers instead, because the underlying API endpoints paginate
differently: KeyValueStoreClient.ListKeys returns KeyValueStoreKeysPage (key-based
pagination) and RequestQueueClient.ListHead returns RequestQueueHead. Both are documented on
the storages page.
- Actors — Actors, versions, environment variables.
- Builds — Actor builds.
- Runs — Actor runs and their default storages.
- Tasks — Actor tasks.
- Storages — Datasets, key-value stores, request queues.
- Schedules — Schedules.
- Webhooks — Webhooks and webhook dispatches.
- Misc — Apify Store, users, logs.
Full runnable programs are in ../examples and are tested in CI.