Tutorials

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

  1. Create a token with the search ability under API tokens. Choose a short lifetime. An organization admin can set a credit limit for the token.
  2. Store the token in the tool credential store, never in the flow text.
  3. Create two labels in Gmail: legal-question and klaracase-checked. Only emails with legal-question trigger 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.

  1. 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 returns Subject, From, id and threadId, but no mail body.
  2. 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, value Bearer <your token>. Enable "Send Query Parameters". Set query to the expression $json.Subject.slice(0, 500), which cuts the subject at 500 characters. A subject under 2 characters returns status 422. Set limit to 3.
  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.
  4. 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 expression Object.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.threadId and "To Email" to $('Gmail Trigger').item.json.From. After the HTTP Request, $json is the API answer, so the mail fields come from the trigger node by its name.
  5. Gmail, resource "Message", operation "Add Label": set "Message ID" to the expression $('Gmail Trigger').item.json.id. Under "Label Names or IDs" pick klaracase-checked from the list. The label must exist in Gmail first, see "Prepare".

The ready-made n8n workflow file is in the klaracase examples repository.

Zapier

  1. Trigger Gmail, "New Email Matching Search": search label:legal-question. The trigger polls regularly for emails from the past hour.
  2. Action "Webhooks by Zapier", event "GET": target the URL above. In the "Data" fields, set query to the subject and limit to 3. Under "Headers", set Authorization to Bearer <your token>. Zapier displays the response fields after testing.
  3. Gmail, "Create Draft Reply": provide the email "Thread ID" and insert the sources into the body.
  4. 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.

All tutorials