E-mail triage with Gmail and the klaracase API, no code
A mail with a legal question triggers a search in klaracase. The flow adds a label and drafts a reply with the sources. With n8n or Zapier.
An n8n or Zapier flow reads emails containing legal questions, queries the klaracase API for matching decisions and statutes, labels the email in Gmail, and drafts a reply with the sources. It sends nothing. You review the draft and verify each source before replying.
Prepare
- Create a token with the
searchability under API tokens. Choose a short lifetime. An organization admin can set a credit limit for the token. - Store the token in the tool credential store, never in the flow text.
- Create two labels in Gmail:
legal-questionandklaracase-checked. Only emails withlegal-questiontrigger the flow. This controls what the tool reads and when it spends credits.
The call
Each email triggers one call:
GET https://klaracase.de/api/v1/search
Authorization: Bearer <your token>
query=<legal question> limit=3
query accepts 2 to 500 characters. limit applies per section: limit=3 returns up to 3 hits in each section. The response contains sections.decisions, sections.laws and sections.guidance (administrative guidance such as BMF letters). A section without hits can be missing. Each hit includes fundstelle and corpus_url. Find all fields in the API reference.
n8n
Tested with n8n 2.49.5. Menu names can differ in other versions. The Gmail steps follow the field names in the n8n node definition. Run them once with a test mail before you rely on them.
In n8n, an expression is a field in "Expression" mode with the code between two opening and two closing curly braces. The expressions below are written without the braces.
- Gmail Trigger: event "Message Received". Set the interval in minutes under "Poll Times". Under "Filters" add "Search" with
label:legal-question. Set "Read Status" to "Unread and read emails", or a mail you opened already does not start the flow. Authenticate via Google OAuth2. Leave "Simplify" enabled. It returnsSubject,From,idandthreadId, but no mail body. - HTTP Request: method GET, using the URL above. Under "Authentication" select "Generic Credential Type", then under "Generic Auth Type" select "Header Auth". Create a credential: name
Authorization, valueBearer <your token>. Enable "Send Query Parameters". Setqueryto the expression$json.Subject.slice(0, 500), which cuts the subject at 500 characters. A subject under 2 characters returns status 422. Setlimitto 3. - If: add the condition "Number", "is greater than" 0 on the expression
Object.values($json.sections).flat().length. A search without hits returns empty lists, so this step prevents empty drafts. - Gmail, resource "Draft", operation "Create": set "Subject" to
Re:followed by the expression$('Gmail Trigger').item.json.Subject, and "Email Type" to "Text". In "Message", use the expressionObject.values($json.sections).flat().map(h => '- ' + h.fundstelle + ' ' + h.corpus_url).join('\n'). A single dragged field inserts only the first hit; this expression lists all hits. Under "Options" set "Thread ID" to$('Gmail Trigger').item.json.threadIdand "To Email" to$('Gmail Trigger').item.json.From. After the HTTP Request,$jsonis the API answer, so the mail fields come from the trigger node by its name. - Gmail, resource "Message", operation "Add Label": set "Message ID" to the expression
$('Gmail Trigger').item.json.id. Under "Label Names or IDs" pickklaracase-checkedfrom the list. The label must exist in Gmail first, see "Prepare".
The ready-made n8n workflow file is in the klaracase examples repository.
Zapier
- Trigger Gmail, "New Email Matching Search": search
label:legal-question. The trigger polls regularly for emails from the past hour. - Action "Webhooks by Zapier", event "GET": target the URL above. In the "Data" fields, set
queryto the subject andlimitto 3. Under "Headers", setAuthorizationtoBearer <your token>. Zapier displays the response fields after testing. - Gmail, "Create Draft Reply": provide the email "Thread ID" and insert the sources into the body.
- Gmail, "Add Label to Email": apply the label for checked emails.
Per the Zapier help documentation, Webhooks by Zapier is not available on the Free plan. You need a paid plan. Check the Zapier pricing page before setup.
Zapier lacks a dedicated credential store for this step. The token sits in the step "Headers" field, visible to anyone who can edit the Zap. Use a dedicated token restricted to the search ability and a credit limit. Revoke it when staff leave. Zapier advises against storing credentials in global variables.
Cost
Each search costs 1 credit. Duplicate searches in the same credit period and searches with zero hits cost nothing. The response credits field shows the query cost and remaining balance. New accounts receive 30 starter credits. When credits run out, the API returns 402, charges nothing, and stops the flow. Read more on the credits page and in the pricing.
Privacy
Send only the legal question. Never include email body text or client names. If you cannot omit a name, pseudonymise the text first with klaracase N.N.. Data processors are listed under Privacy and security.
Finally
klaracase does not verify whether a decision remains good law. Open every source via corpus_url and verify the original text before you use the draft.