Skip to content

About

Unofficial .NET client for the Quickbase REST API with typed record mapping, paging, batched upserts and retries

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

41 Commits

Folders and files

Repository files navigation

QuickbaseNet

A .NET client for the Quickbase REST API v1 with typed record mapping, automatic paging, batched upserts and retries.

Build NuGet Downloads License: MIT

Unofficial library. Not affiliated with Quickbase, Inc.

dotnet add package QuickbaseDotNet

The package is QuickbaseDotNet and the namespace is QuickbaseNet.

Quick start

using QuickbaseNet;

var qb = new QuickbaseClient(new QuickbaseOptions { Realm = "acme", UserToken = token });

var page = await qb.Records.QueryAsync(new RecordQuery
{
    From = "bqx7xre7m",
    Select = [3, 6, 7],
    Where = Filter.Fid(7).Is("Open").And(Filter.Fid(9).Over(1000)),
    SortBy = [Sort.Asc(6)],
});

foreach (var record in page.Records)
{
    Console.WriteLine($"{record.Rid}: {record.GetString(6)} ({record.GetDecimal(9):C})");
}

Operations are grouped by resource: qb.Records, qb.Reports, qb.Apps, qb.Tables and qb.Fields. Every async method takes a CancellationToken.

A Record is a read-only map of fid to JsonElement with the {"value": ...} wrapper already removed. The getters (GetString, GetDecimal, GetInt64, GetBoolean, GetDate, GetDateTime and Get<T>) return null for empty fields and accept numbers that Quickbase sends as strings, which formula fields often do.

Typed mapping

Put [Fid] on the properties of a partial class:

public sealed partial class Project
{
    [Fid(3)] public long Rid { get; set; }
    [Fid(6)] public string? Name { get; set; }
    [Fid(7)] public string? Status { get; set; }
    [Fid(9)] public decimal Budget { get; set; }
    [Fid(10)] public DateOnly? Due { get; set; }
    [Fid(12, ReadOnly = true)] public decimal? Spent { get; set; }
}

A source generator in the package writes the mapping code at compile time, so there is no reflection at runtime and the mapping works under trimming and Native AOT. The generic overloads select the mapped fids for you:

var open = await qb.Records.QueryAsync<Project>(new RecordQuery { From = tableId, Where = Filter.Fid(7).Is("Open") });

await foreach (var project in qb.Records.QueryAllAsync<Project>(new RecordQuery { From = tableId }))
{
    Console.WriteLine($"{project.Name} is due {project.Due}");
}

ReadOnly = true fields are read but never written, which is what you want for lookups, formulas and summaries.

If a type cannot get a generated mapper you get a build warning that says why (QBN001 to QBN004): the type is not partial, a property type has no conversion or the type has no public parameterless constructor. For those cases there is a reflection fallback. It is marked [RequiresUnreferencedCode] so the trimmer tells you when you use it:

var mapper = RecordMapper.Reflection<LegacyProject>();
var page = await qb.Records.QueryAsync(new RecordQuery { From = tableId }, mapper);

On a 1,000 record benchmark the generated mapper reads about twice as fast as the reflection one and allocates about 40% less. Run benchmarks/QuickbaseNet.Benchmarks to see numbers for your machine.

Paging

QueryAllAsync returns IAsyncEnumerable<Record> and fetches pages as you enumerate:

var query = new RecordQuery
{
    From = tableId,
    Where = Filter.Fid(2).OnOrAfter(DateTimeOffset.UtcNow.AddDays(-1)),
    Options = new QueryOptions { Top = 500 },
};

await foreach (var record in qb.Records.QueryAllAsync(query))
{
    Console.WriteLine(record.Rid);
}

Top is the page size here, not a limit on the total. Quickbase caps each response by payload size as well, so a page can come back with fewer records than you asked for even when more remain. The pager moves skip forward by the number of records that actually arrived and stops when it reaches totalRecords or gets an empty page. Code that adds top to skip on every request silently drops records on wide tables; this is the most common bug in hand-written Quickbase paging.

Reports page the same way:

await foreach (var record in qb.Reports.RunAllAsync(tableId, reportId: "7", pageSize: 1000))
{
    Console.WriteLine(record.GetString(6));
}

Upserts

var result = await qb.Records.UpsertAsync(tableId,
[
    new RecordData { [6] = "Bridge retrofit", [7] = "Open", [9] = 125_000m, [10] = new DateOnly(2026, 9, 30) },
    new RecordData { [6] = "Depot roof", [7] = "Planned" },
],
new UpsertOptions { MergeFieldId = 6, FieldsToReturn = [3] });

Console.WriteLine($"{result.CreatedRecordIds.Count} created, {result.UpdatedRecordIds.Count} updated");
foreach (var (row, errors) in result.LineErrors)
{
    Console.WriteLine($"Row {row}: {string.Join("; ", errors)}");
}

Typed objects work too: await qb.Records.UpsertAsync(tableId, projects).

What the client does for you:

  • Records go out in batches of BatchSize (1,000 by default) and the results are merged.
  • LineErrors row numbers point into the list you passed in. Quickbase numbers them per request, so without renumbering an error in the third batch would claim to be row 2.
  • Null values are skipped so a partly filled object never blanks out fields. Set WriteNulls = true to clear fields on purpose.
  • Fids 1, 2, 4 and 5 (Date Created, Date Modified, Record Owner, Last Modified By) are never sent.
  • Record ID# (fid 3) is only sent when it is the merge field, either because MergeFieldId is 3 or because no merge field is set and the table's key field applies.
  • Dates are written as yyyy-MM-dd and date/times as ISO 8601 in UTC.

Deletes

var deleted = await qb.Records.DeleteAsync(tableId, Filter.Fid(7).Is("Cancelled").And(Filter.Fid(2).Before(new DateOnly(2024, 1, 1))));

An empty where clause throws ArgumentException before anything is sent. If you really want to empty a table, say so with a filter like Filter.Fid(3).Over(0).

Filters

Filter builds Quickbase query strings and converts to string wherever a where clause is expected.

var where = Filter.All(
    Filter.Fid(7).Is("Open"),
    Filter.Any(Filter.Fid(8).Is("East"), Filter.Fid(8).Is("West")),
    Filter.Fid(9).AtLeast(1000));
// {7.EX.'Open'}AND({8.EX.'East'}OR{8.EX.'West'})AND{9.GTE.'1000'}
Method Operator Method Operator
Is EX IsNot XEX
Contains CT DoesNotContain XCT
StartsWith SW DoesNotStartWith XSW
Has HAS DoesNotHave XHAS
Under LT AtMost LTE
Over GT AtLeast GTE
Before BF OnOrBefore OBF
After AF OnOrAfter OAF
InRange IR NotInRange XIR
TrueValue TV IsChecked / IsUnchecked EX 'true' / 'false'
IsBlank EX '' IsNotBlank XEX ''

Mixed groups get parentheses, chains of the same joiner stay flat and Filter.Raw("...") wraps anything you wrote by hand. Numbers and dates are formatted with the invariant culture, so a server running in de-DE still sends 1234.5 and single quotes in values are escaped.

Dependency injection

dotnet add package QuickbaseDotNet.Extensions.DependencyInjection
builder.Services.AddQuickbase(builder.Configuration.GetSection("Quickbase"));
{
  "Quickbase": {
    "Realm": "acme",
    "UserToken": "b1234_xyz",
    "Retry": { "MaxRetries": 5 }
  }
}

Options are validated at startup, so a missing realm or token fails the host instead of the first request. The client comes from IHttpClientFactory with RetryHandler attached. Inject QuickbaseClient anywhere.

For more than one realm, register names and resolve them as keyed services or through QuickbaseClientFactory:

builder.Services.AddQuickbase("east", builder.Configuration.GetSection("Quickbase:East"));
builder.Services.AddQuickbase("west", builder.Configuration.GetSection("Quickbase:West"));

public sealed class Reconciler([FromKeyedServices("east")] QuickbaseClient east, [FromKeyedServices("west")] QuickbaseClient west);

AddQuickbase returns the IHttpClientBuilder, so you can replace the built-in retries with Microsoft.Extensions.Http.Resilience:

builder.Services.AddQuickbase(builder.Configuration.GetSection("Quickbase"))
    .RemoveRetryHandler()
    .AddStandardResilienceHandler();

To pull the token from somewhere else at runtime, set TokenSource. It is called before each request, so cache inside it:

builder.Services.AddOptions<QuickbaseOptions>()
    .Configure<VaultToken>((options, vault) => options.TokenSource = vault.GetAsync);

AI tools

dotnet add package QuickbaseDotNet.AI

AsAITools turns a client into Microsoft.Extensions.AI tools, so any IChatClient can read your Quickbase data. That covers OpenAI, Azure OpenAI, Ollama and Anthropic clients, Semantic Kernel and Microsoft Agent Framework.

using Microsoft.Extensions.AI;
using QuickbaseNet.AI;

var tools = qb.AsAITools(new QuickbaseToolOptions { Apps = { "bqx7a9k2m" } });

using var chat = chatClient.AsBuilder().UseFunctionInvocation().Build();
var answer = await chat.GetResponseAsync("Which open projects are over budget?", new ChatOptions { Tools = tools });

The model gets quickbase_get_app, quickbase_list_tables, quickbase_describe_table, quickbase_query_records and quickbase_run_report. Records come back keyed by field label, with a next_skip when there are more.

  • Allowlisted. Only the apps in Apps are reachable. A table from any other app is refused before a record call is made.
  • Read only by default. AllowWrites = true adds quickbase_upsert_records and quickbase_delete_records. They are wrapped in ApprovalRequiredAIFunction, so the chat loop stops and asks your app before each write. Set RequireApprovalForWrites = false only for unattended jobs you trust.
  • Bounded. MaxRecords (100) caps every read and write and MaxTextLength (1,000) cuts long text so one rich text field cannot fill the context window.
  • Data, not instructions. Every page of records carries a notice telling the model that record text is data and must never be followed as instructions, which blunts prompt injection through stored values.
  • Recoverable errors. A bad field ID, filter or table comes back to the model as {"error": "..."} with the Quickbase message, so it can fix the call instead of giving up.
  • AOT safe. The tools use hand-written JSON schemas instead of reflection.

Use NamePrefix to tell two realms apart in one chat. For Claude Desktop, Copilot or Cursor, use the MCP server instead; it wraps the same SDK.

Coding agents

The repository ships an agent skill that teaches Claude Code, GitHub Copilot, Cursor and other agents how to use this SDK, including the paging, upsert and sync mistakes to avoid. In Claude Code:

/plugin marketplace add gitshrini/QuickbaseNet
/plugin install quickbasenet@quickbasenet

For Copilot or any tool that reads .github/skills, .claude/skills or .agents/skills, copy skills/quickbasenet into that folder. llms.txt points tools that read it at the same docs.

Azure Functions sample

samples/FunctionsSync is an isolated worker app on .NET 10. A timer trigger runs every 15 minutes, reads the projects changed since the last run and merges them into Azure SQL. The Function App's managed identity reads the Quickbase token from Key Vault and signs in to Azure SQL, so no secret sits in app settings.

Two files are worth reading. VaultToken.cs caches the secret for ten minutes so rotation needs no restart. SyncProjects.cs pages by key rather than by offset and explains why: an edit made while the sync reads moves a record to the end of the Date Modified order, and offset paging would skip the record behind it for good. sql/schema.sql has the tables.

Observability

Every call starts an Activity from the QuickbaseNet source with quickbase.realm, quickbase.operation and quickbase.table.id tags. The QuickbaseNet meter publishes:

Instrument Type Unit
quickbase.client.request.duration Histogram s
quickbase.client.retries Counter {retry}
quickbase.client.records.returned Counter {record}
builder.Services.AddOpenTelemetry()
    .WithTracing(t => t.AddSource(QuickbaseTelemetry.ActivitySourceName))
    .WithMetrics(m => m.AddMeter(QuickbaseTelemetry.MeterName));

Logs go through ILogger with the QuickbaseNet category. Requests log at Debug, retries at Information and failures at Warning. Tokens are never logged.

Error handling

Any non-success response becomes a QuickbaseException:

try
{
    await qb.Records.QueryAsync(new RecordQuery { From = tableId, Where = "{99.EX.'x'}" });
}
catch (QuickbaseException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
{
    Console.WriteLine($"{ex.QuickbaseMessage}: {ex.Description} (ray {ex.RequestId})");
}

RequestId is the QB-API-RAY header, which Quickbase support asks for. ResponseBody holds the raw body. Gateways in front of Quickbase sometimes answer with HTML instead of JSON; those bodies are kept as text and QuickbaseMessage falls back to the HTTP reason phrase.

Retries

RetryHandler retries 429, 502, 503 and 504. It honors Retry-After in either the seconds or the date form. Without that header it waits BaseDelay * 2^(attempt - 1), capped at MaxDelay, then picks a random point in the upper half of that window so a burst of throttled clients does not retry in lockstep. Request bodies are buffered so every attempt sends the same bytes. Waits go through TimeProvider, which is how the tests check timing without sleeping.

A POST that hit a 502 or 504 may have been processed before the gateway gave up. Upserts with a merge field are safe to repeat. Upserts that create records without one can create a duplicate on retry; set MergeFieldId or lower MaxRetries for those.

Options

Option Default Notes
Realm required acme or acme.quickbase.com
UserToken Sent as QB-USER-TOKEN
TempToken Sent as QB-TEMP-TOKEN
TokenSource Async callback for tokens from a vault. Set exactly one of the three token options
UserAgent Your app's product token, sent before QuickbaseNet/{version}
BaseAddress https://api.quickbase.com/v1/ Change only for a proxy
Timeout 100 s Applies when the client creates its own HttpClient or comes from DI
Retry.MaxRetries 3 Zero turns retries off
Retry.BaseDelay 1 s First backoff step
Retry.MaxDelay 30 s Cap for backoff and for Retry-After

Supported frameworks

The packages target net10.0 and netstandard2.0. That covers .NET 10 and later, the .NET 8 and 9 runtimes through netstandard2.0 and .NET Framework 4.6.2 and later. The net10.0 build is trimmable and Native AOT compatible. Generated mapping code compiles as C# 7.3, so it works in old-style .NET Framework projects too.

Roadmap

  • Field and table management endpoints (create, update, delete)
  • Temporary token exchange through /auth/temporary
  • File attachment upload and download
  • Formula evaluation through /formula/run
  • An IAsyncEnumerable overload for upserts that streams batches from a source you do not want in memory

Building

dotnet build
dotnet test
dotnet pack -c Release -o artifacts

Integration tests run against a real realm only when QB_REALM, QB_TOKEN and QB_TABLE_ID are set and skip otherwise. Set QB_ALLOW_WRITES=1 as well to run the test that creates and deletes a record.

Every C# block in this README is compiled by tests/ReadmeSnippets on each build, so the examples cannot drift from the API.

See CONTRIBUTING.md before opening a pull request.

About

Unofficial .NET client for the Quickbase REST API with typed record mapping, paging, batched upserts and retries

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages