Guide · C# (.NET)
Async PDF rendering with a verified webhook in C# (.NET)
A long report should not hold an HTTP request open. In async mode the API answers at once with a queued render and calls your endpoint when the PDF is ready. This guide has both halves in C# (.NET): the request, and a receiver that accepts only deliveries Formfeed really signed.
Free plan with 100 units a month, no credit card

What you need
- An API key. Create one in the app under API keys and export it as
FORMFEED_API_KEY. A test key (ff_test_…) is right for trying things out. See the quick start. - C# (.NET). You need the .NET 8 SDK or newer and the
Formfeedpackage from NuGet. - The template.
revenue-reportfrom the report example, and itsdata.jsonnext to the program. - A secret. 16 to 200 random characters in
FORMFEED_WEBHOOK_SECRET, known to both programs. It signs the deliveries of this render, retries included. - A public URL. Replace
https://example.com/hooks/formfeedwith your endpoint. While developing,formfeed listenforwards deliveries tolocalhostwithout a tunnel.
dotnet new console -o render && cd render
dotnet add package Formfeed # then replace Program.csThe program
The request names the template, switches to mode: "async" and says where to report. The answer comes back immediately with the status queued.
using System.Text.Json;
using Formfeed;
using var formfeed = new FormfeedClient(Environment.GetEnvironmentVariable("FORMFEED_API_KEY"));
var data = JsonSerializer.Deserialize<Dictionary<string, object?>>(File.ReadAllText("data.json"));
// a problem answer (4xx, 5xx) throws a FormfeedException with the API's code and detail
var render = await formfeed.Renders.CreateAsync(new RenderRequest
{
Template = "revenue-report",
Data = data,
Mode = "async",
WebhookUrl = "https://example.com/hooks/formfeed",
WebhookSecret = Environment.GetEnvironmentVariable("FORMFEED_WEBHOOK_SECRET"),
});
Console.WriteLine($"{render.Id} {render.Status}"); // queued: the webhook reports the restRun it
It prints the render’s id and queued. A few seconds later your endpoint receives render.completed with the full render, its download_url included, or render.failed with the reason.
export FORMFEED_API_KEY=ff_test_...
export FORMFEED_WEBHOOK_SECRET=$(openssl rand -hex 24)
dotnet runWhat is particular about C# (.NET)
- Requests are classes. A request is a class with the API’s fields as properties (
RenderRequest,ProtectOptions), and what is left null is not sent; free maps such asData,SettingsandPostare dictionaries. The answer is aRender:DownloadUrl,PageCountandUnitsare properties, andRawholds the whole answer. - Retries are built in. The client sends an
Idempotency-Keywith every render and retries429,503and network errors up to three times with backoff, with the same key: a retry of a request that was answered already gets that answer back instead of a second render. - One client, async throughout. Every call of the client is
…Asyncand takes aCancellationToken. It sends over anHttpClientof its own, or the one you pass, such as one fromIHttpClientFactory, and serves any number of calls at the same time: make it once and keep it. - Trimming and native AOT. The SDK’s JSON is generated at build time, so an application that uses it can be trimmed and compiled ahead of time. An object of your own inside
Datathen needsJsonSerializerOptionswhose resolver knows its type; dictionaries, lists and JSON values need nothing.
The receiver
It listens on port 8080, reads the raw body, checks the signature and the age of the timestamp, and only then looks at the JSON. A delivery that fails the check gets 401.
// dotnet new web && dotnet add package Formfeed, then replace Program.cs
using Formfeed;
var app = WebApplication.CreateBuilder(args).Build();
var secret = Environment.GetEnvironmentVariable("FORMFEED_WEBHOOK_SECRET")!;
app.MapPost("/hooks/formfeed", async (HttpRequest request) =>
{
// the signature covers the bytes on the wire: read the raw body, never re-serialised JSON
using var body = new MemoryStream();
await request.Body.CopyToAsync(body);
try
{
// checks the HMAC and the five-minute tolerance, throws when either fails
var delivery = Webhook.Parse(secret, request.Headers["Webhook-Signature"], body.ToArray());
if (delivery.Type == "render.completed")
{
var render = Render.FromJson(delivery.Data);
Console.WriteLine($"done {render.Id} {render.DownloadUrl}");
}
else if (delivery.Type == "render.failed")
{
Console.WriteLine($"failed {Render.FromJson(delivery.Data).Id}");
}
return Results.NoContent();
}
catch (WebhookSignatureException)
{
return Results.Unauthorized();
}
});
app.Run("http://0.0.0.0:8080");Start the receiver
dotnet new web -o hook && cd hook
dotnet add package Formfeed # replace Program.cs, then:
FORMFEED_WEBHOOK_SECRET=… dotnet runVerifying in C# (.NET)
- One call verifies.
Webhook.Parsechecks the HMAC, compared in constant time, and the five-minute tolerance, and throwsWebhookSignatureExceptionwhen either fails;Webhook.Verifyanswerstrueorfalseinstead. - Read the stream. Do not bind the body to a model in the endpoint’s signature: model binding parses the JSON, and the signature covers the bytes as they arrived.
What arrives
A POST with Webhook-Signature: t=<unix seconds>,v1=<hex>, where the hex is HMAC-SHA256 over t, a dot and the raw body, keyed with your secret exactly as you have it, as UTF-8 bytes: the webhook_secret you sent, or a registered endpoint’s whole whsec_… string, prefix included. Every attempt is signed anew with its own t. Webhook-Id stays the same across retries, so it is your deduplication key. data is the render as GET /renders/{id} returns it:
{
"id": "evt_5b0c8e6f2d4a4c3e9b1a7f6e5d4c3b2a",
"type": "render.completed",
"created_at": "2026-09-18T10:42:00Z",
"workspace_id": "3a6f…",
"data": {
"id": "rnd_7da09ab6cd9946b798c187c2a9350852",
"status": "succeeded",
"download_url": "https://cdn.formfeed.dev/o/eu/…/document.pdf?exp=…&sig=…",
"page_count": 2,
"units": 1,
…
}
}Retries, and what your endpoint owes
- Answer fast. A delivery succeeds with a
2xxwithin 10 seconds. Store the event and do the work afterwards. - Retries. Anything else, a redirect included, is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours: six attempts in all, over about 14 hours and 40 minutes. The same event can therefore arrive twice: deduplicate by
Webhook-Id. - Without a secret. A
webhook_urlwithoutwebhook_secretis delivered unsigned. For signed deliveries of every render, register an endpoint once in the app or throughPOST /webhooks; it gets its own secret. - Try it locally.
formfeed listen --forward-to http://localhost:8080/hooks/formfeedrelays the events of your test renders to your machine, signed with the session’s own secret rather thanwebhook_secret: start the receiver with that one, whichformfeed listen --print-secretprints (run it before the session, since it ends a running one).formfeed trigger render.completed --template revenue-reportmakes a real test render whose event you watch arrive. The key needs thewebhook:listenscope. See developing webhooks locally.
When the API says no
- One shape for every error. Errors are problem documents (RFC 9457) with
type,title,status,detail, a stablecodeand therequest_idto quote to support; thetypeURL leads to a page about that error. The list is in the error reference. - The usual ones.
401 unauthorizedfor a missing or revoked key,404 template_not_foundfor a wrong template name,422 template_runtime_errorwhen the template fails on the data,429 rate_limitedabove the plan’s requests per second,402 quota_exceededwhen the Free plan’s units are used up (a paid plan bills extra units up to its hard cap). - Retry safely. Send an
Idempotency-Keyheader with the POST, and repeat the request with the same key when you do not know whether the first attempt arrived: for 24 hours the key returns the first answer instead of rendering and billing again. The answer is stored once the first attempt has been answered, so do not retry while it may still run; and problems below 500 are stored too, so a corrected request needs a new key.
The job around this program
This guide is one program. What the job needs around it, from the template to the limits and the price, is on the page Report PDF generation.
More C# (.NET) guides
FAQ
- Can I poll instead of receiving a webhook?
- Yes:
GET /renders/{id}until the status issucceededorfailed; the SDKs havewaitFor,wait_for,WaitForandWaitForAsyncfor it. A webhook saves the requests and reports sooner. See async and batch. - Why must the raw body be used?
- The signature covers the bytes on the wire. Parsing and re-serialising JSON may reorder keys, change number formats or escape characters differently, and the HMAC of that text no longer matches.
- What is the five-minute tolerance for?
- It stops a captured delivery from being replayed later. It also means the clock of your server must be roughly right.