Elixir client for the Quickbase JSON RESTful API, built on Req.

  • Query records, run saved reports, upsert and delete records, list fields and tables
  • stream_records/2 lazily pages through large result sets
  • Transient failures on read calls retried automatically (Req built-in retry)
  • Helpers for Quickbase's field-id-keyed row format (value/2, by_label/3)
  • Easy to test: pass any Req option through new/1, including plug: {Req.Test, ...}

Installation

def deps do
  [
    {:quickbase, "~> 0.1.0"}
  ]
end

Usage

client = Quickbase.new(realm: "demo.quickbase.com", token: System.fetch_env!("QB_USER_TOKEN"))

# Query records
{:ok, %{"data" => rows, "fields" => fields}} =
  Quickbase.query_records(client,
    from: "bck7gp3q2",
    select: [3, 6, 7],
    where: "{'6'.EX.'Done'}",
    sort_by: [%{"fieldId" => 6, "order" => "ASC"}]
  )

# Unwrap values by field id or label
idx = Quickbase.label_index(fields)

for row <- rows do
  {Quickbase.value(row, 3), Quickbase.by_label(row, idx, "Status")}
end

# Stream every record, paging automatically
client
|> Quickbase.stream_records(from: "bck7gp3q2", select: [3])
|> Enum.count()

# Run a saved report
{:ok, report} = Quickbase.run_report(client, 7, "bck7gp3q2")

# Insert/update records
Quickbase.upsert_records(client, "bck7gp3q2", [
  %{"6" => %{"value" => "New task"}}
])

# Delete records
Quickbase.delete_records(client, "bck7gp3q2", "{'3'.EX.'42'}")

Every function has a bang variant (query_records!/2, ...) that returns the body directly and raises Quickbase.Error (API error) or a transport exception on failure.

Testing your app

new/1 forwards unknown options to Req.new/1, so stub responses with Req.Test:

client = Quickbase.new(realm: "r", token: "t", plug: {Req.Test, MyStub})

Req.Test.stub(MyStub, fn conn ->
  Req.Test.json(conn, %{"data" => []})
end)

License

MIT