ApifyClient.Actors (apify_client v1.0.0)

Copy Markdown View Source

Run Actors.

Actors can be referred to by ID ("vKg4IjxZbEYTYeW8T") or by name, as "username/actor-name" or "username~actor-name".

# Start a run and return right away
{:ok, run} = ApifyClient.Actors.start("apify/web-scraper", %{"startUrls" => [...]})

# Start a run and wait for it to finish
{:ok, run} = ApifyClient.Actors.call("apify/web-scraper", input, memory: 1024)
{:ok, items} = ApifyClient.Datasets.list_items(run.default_dataset_id)

Functions take the connection options described in ApifyClient.Client (:token, :config, ...) next to their own. For everything else about Actors, see ApifyClient.API.Actors and the modules below it.

Summary

Functions

Builds a version of an Actor and returns the build without waiting for it to finish; wait with ApifyClient.Builds.wait_for_finish/2.

Starts an Actor and waits for the run to finish.

Gets an Actor.

Converts an Actor name to the form used in API paths: "username/actor-name" becomes "username~actor-name". IDs are returned unchanged.

Starts an Actor and returns the run without waiting for it to finish.

Functions

build(actor_id, version_number, opts \\ [])

@spec build(String.t(), String.t(), keyword()) ::
  {:ok, ApifyClient.Schemas.Build.t()} | {:error, ApifyClient.Error.t()}

Builds a version of an Actor and returns the build without waiting for it to finish; wait with ApifyClient.Builds.wait_for_finish/2.

Options

  • :tag - tag to give the build when it succeeds (default: the version's build tag, usually latest)
  • :use_cache - use cached Docker layers
  • :beta_packages - install beta versions of Apify NPM packages
  • :wait_for_finish - seconds (at most 60) the API waits for the build to finish before responding

call(actor_id, input \\ nil, opts \\ [])

@spec call(String.t(), term(), keyword()) ::
  {:ok, ApifyClient.Schemas.Run.t()} | {:error, ApifyClient.Error.t()}

Starts an Actor and waits for the run to finish.

Takes the options of start/3, plus:

  • :wait_secs - stop waiting after this many seconds and return the run as it is then; check it with ApifyClient.Runs.finished?/1. Default: wait as long as it takes.

The run is returned whatever its final status; use ApifyClient.Runs.succeeded?/1 to check it.

get(actor_id, opts \\ [])

@spec get(String.t(), keyword()) ::
  {:ok, ApifyClient.Schemas.ActorResource.t()} | {:error, ApifyClient.Error.t()}

Gets an Actor.

safe_id(actor_id)

@spec safe_id(String.t()) :: String.t()

Converts an Actor name to the form used in API paths: "username/actor-name" becomes "username~actor-name". IDs are returned unchanged.

iex> ApifyClient.Actors.safe_id("apify/web-scraper")
"apify~web-scraper"

start(actor_id, input \\ nil, opts \\ [])

@spec start(String.t(), term(), keyword()) ::
  {:ok, ApifyClient.Schemas.Run.t()} | {:error, ApifyClient.Error.t()}

Starts an Actor and returns the run without waiting for it to finish.

input is the Actor input: a map (sent as JSON with the keys as given, so use the names the Actor expects, usually camelCase), a binary with :content_type, or nil to use the Actor's default input.

Options

  • :build - build tag or number to run (default: the Actor's default build)
  • :memory - memory limit in megabytes (a power of 2, at least 128)
  • :timeout - run timeout in seconds
  • :max_items - maximum number of dataset items charged (pay-per-result Actors)
  • :max_total_charge_usd - maximum total cost of the run (pay-per-event Actors)
  • :restart_on_error - restart the run if it fails
  • :wait_for_finish - seconds (at most 60) the API waits for the run to finish before responding
  • :webhooks - webhooks for this run, as a list of maps (for example [%{"eventTypes" => ["ACTOR.RUN.SUCCEEDED"], "requestUrl" => url}])
  • :content_type - content type of a binary input