### Fetch All Objects with `all/2` and Pagination Source: https://hexdocs.pm/ex_nylas Use `all/2` to retrieve all objects of a given type, with the SDK handling pagination. Configure request throttling with `delay` and process pages as they arrive using `send_to`. ```elixir conn = %ExNylas.Connection{api_key: "1234", grant_id: "1234"} # Accumulate results in memory and return them when paging is complete {:ok, []} = ExNylas.Messages.all(conn, query: [any_email: "nick@example.com", fields: "include_headers"]) # Send results to a handler as each page is received {:ok, []} = ExNylas.Messages.all(conn, send_to: &IO.inspect/1, delay: 3_000, query: [any_email: "nick@example.com", fields: "include_headers"]) # Or handle paging on your own {:ok, first_page} = ExNylas.Messages.list(conn, limit: 50) {:ok, second_page} = ExNylas.Messages.list(conn, limit: 50, page_token: first_page.next_cursor) ``` -------------------------------- ### Initialize ExNylas Connection Source: https://hexdocs.pm/ex_nylas Create a connection struct with your Nylas API credentials and server details. The `access_token` is optional if using `grant_id` and `api_key`. Additional options are passed to the Req HTTP client. ```elixir conn = %ExNylas.Connection{ client_id: "1234", api_key: "1234", grant_id: "1234", access_token: "1234", # Omited if using `grant_id` + `api_key` api_server: "https://api.us.nylas.com", options: [], # Passed to Req (HTTP client) telemetry: true # Enables telemetry and the default telemetry logger (defaults to `false`) } ``` -------------------------------- ### Configure Req HTTP Client Options Source: https://hexdocs.pm/ex_nylas Customize the behavior of the underlying Req HTTP client by providing options in the `ExNylas.Connection` struct. Do not override `decode_body` as the SDK relies on Req for response decoding. ```elixir [ retry: :safe_transient, cache: false, compress_body: false, compressed: true, # ask server to return compressed responses receive_timeout: 15_000, # socket receive timeout pool_timeout: 5000 # pool checkout timeout ] ``` -------------------------------- ### Pass Queries and Filters as Maps or Keyword Lists Source: https://hexdocs.pm/ex_nylas When making API requests that support queries or filters, you can pass them as a map or a keyword list. ```elixir conn = %ExNylas.Connection{api_key: "1234", grant_id: "1234"} {:ok, threads} = ExNylas.Threads.list(conn, limit: 5) {:ok, threads} = ExNylas.Threads.list(conn, %{limit: 5}) ``` -------------------------------- ### Handle API Responses with Ok/Error Tuples or Exceptions Source: https://hexdocs.pm/ex_nylas ExNylas functions can return an `{:ok, result}` or `{:error, reason}` tuple, or raise an exception if using the `!/1` variant. ```elixir conn = %ExNylas.Connection{api_key: "1234", grant_id: "1234"} # Returns {:ok, result} or {:error, reason} {:ok, message} = ExNylas.Messages.first(conn) # Returns result or raises an exception message = ExNylas.Messages.first!(conn) ``` -------------------------------- ### Validate Data Before Sending with `build/1` Source: https://hexdocs.pm/ex_nylas Optionally use `build/1` to validate data against the Nylas API schema before sending it via `create/update` functions. This leverages Ecto for validation and returns a changeset on error. This functionality is experimental. ```elixir {:ok, folder} = ExNylas.Folders.build(%{name: "Hello World"}) # This will return an error because 'display_name' is not part of the struct ExNylas.Folders.build(%{display_name: "Hello Error"}) > {:error, #Ecto.Changeset valid?: false >} ``` -------------------------------- ### Add ExNylas to Project Dependencies Source: https://hexdocs.pm/ex_nylas Add the ExNylas dependency to your Elixir project's `deps` function in `mix.exs`. ```elixir def deps do [ {:ex_nylas, "~> 0.10.1"} ] end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.