# `Bobbin.Service`
[🔗](https://github.com/heddlehq/Bobbin/blob/main/lib/bobbin/service.ex#L1)

What the nodes that reach other services have in common, for integrations written
in Elixir.

Each action of a service is its own node, so it shows only the fields it needs.
They all use a stored credential, and they answer through the `success` and
`error` outputs, so a flow can handle a service being down.

The host (Heddle) fills templates and keeps credentials, see `Bobbin.Host`.

## Example

```elixir
defmodule Acme.Nodes.GetItem do
  use Bobbin.Node

  @service %{title: "Acme", category: :acme, credential: "acme", icon: "hero-cube"}

  @impl true
  def definition do
    Bobbin.Service.definition(@service, "Get Item", "Reads an item.", [
      %{type: :text, name: :id, label: "Item ID", default: ""}
    ])
  end

  @impl true
  def handler(context, _input) do
    Bobbin.Service.run(context, "acme", fn credential ->
      Acme.get(credential, Bobbin.Service.field(context, "id"))
    end)
  end
end
```

# `content`

Returns what a file field holds.

A field that is a single placeholder can point at what a Download node returned,
which keeps binary files intact from one service to the other.

# `credential`

Returns the values of the credential the node picked, as its flow's workspace sees
it. `refresh: true` renews an OAuth token. See `c:Bobbin.Host.credential/4`.

# `credential_field`

# `definition`

Builds the definition of one action of a service.

# `failure`

# `field`

# `json`

Reads a field that holds JSON, or a single placeholder pointing at a value.

Returns `{:ok, value}` or `{:error, message}`. See `Bobbin.Template.json/3`.

# `media`

Reads a field that holds an image or audio: what another node returned, or a URL.

Returns `{:ok, {bytes, media_type}}` or `{:error, message}`.

# `number`

Reads a field that holds a positive number, or returns `default`.

# `outputs`

# `req_options`

# `run`

Calls `fun` with the credential and answers through the node's outputs.

`fun` returns `{:ok, result}` or `{:error, message}`.

# `success`

# `tls_options`

# `to_file`

Makes a generated file safe to keep in a run's context, in the shape file fields read.

# `to_text`

Makes content safe to keep in a run's context, which is saved as JSON.

# `to_value`

Makes what a driver returned safe to keep in a run's context, which is saved as JSON.

Decimals become strings, because a float would lose cents.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
