Browse API documentation
Implementation guidesv1

Complete server examples

Connect your browser forms to your server with working fetch and upload examples.

On this page

Download a small server-only client and the versioned OpenAPI specification. Both describe the implemented careers API rather than internal workspace endpoints.

Downloads

The client is a reference example, not a separately versioned SDK with a support or automatic retry contract. It requires Node.js 20 or later and uses built-in fetch. Read it before adapting it to your application.

Environment

text
KARWA_API_BASE=http://localhost:8000/api/auth/public/v1
KARWA_APP_KEY=<your-app-key>
KARWA_SECRET_KEY=<your-secret-key>

Use server environment variables. Replace the local base with your deployed HTTPS gateway before production. Never prefix the secret with a browser-exposed environment-variable convention.

List and retrieve

bash
node karwa-api-client.mjs jobs
node karwa-api-client.mjs form JOB_ID POSTING_ID

The jobs command retrieves one page. Use the exported allJobs iterator when you need every result. The form command prints the selected form so you can inspect required questions before creating an application.

javascript
import { KarwaClient } from "./karwa-api-client.mjs";
const api = new KarwaClient();
const posting = await api.job("JOB_ID", "POSTING_ID");
const form = await api.form(posting.id, posting.posting_id);
console.log(form.application_form.sections);

Complete application example

Create a local payload file named applicant.json with top-level identity and consent, custom answers, and a files map from actual file question IDs to local file paths. The files map is a convenience of this example client, not part of Karwa's HTTP submission schema.

json
{
  "full_name": "Example Applicant",
  "email": "applicant@example.com",
  "consent": true,
  "answers": {"experience":"4"},
  "files": {"resume":"./resume.txt"}
}

Set KARWA_IDEMPOTENCY_KEY to one stable identifier for this applicant attempt. Keep it when retrying. Only submit test details to a test company; use an actual applicant's consent in production.

bash
node karwa-api-client.mjs apply JOB_ID POSTING_ID applicant.json

The command fetches the form, validates file question IDs, creates a session, uploads each file and submits the merged answers. It prints the receipt. It requires explicit consent and an idempotency environment variable; it never silently generates a new submission ID on retry. The example reuploads files when rerun; your production implementation should retain successful upload tokens while valid.

Using OpenAPI

Import the JSON into your API client or code generator. Select your local or deployed gateway server and provide both app-key and Bearer-secret security values. The spec includes candidate-facing request/response schemas and the documented required session/idempotency headers. It excludes internal admin routes and key-management routes.

A generated client still needs to render dynamic form questions, observe conditions, collect consent, use raw file bytes and implement stable submission IDs. OpenAPI cannot infer a posting's required fields before you fetch its form.

Do not put production secrets into a shared, browser-hosted API explorer. Keep exported collections free of real credentials and candidate data.

Connect a browser form to your server

Expose only the operations your careers page needs on your own server. For example, your browser can fetch /careers/jobs, /careers/jobs/JOB_ID/form?posting_id=POSTING_ID and submit to /careers/jobs/JOB_ID/apply?posting_id=POSTING_ID. These are routes you implement, not additional Karwa endpoints. Keep your server's company credential fixed; never accept a credential, arbitrary upstream URL or company ID from the browser.

Your jobs handler calls client.jobs. Your form handler calls client.form with the chosen public IDs. Return the form JSON to the browser without adding credential headers or application session tokens to it.

javascript
// Browser code: fetch from YOUR server, never the authenticated Karwa gateway.
const response = await fetch(
  `/careers/jobs/${encodeURIComponent(jobId)}/form?posting_id=${encodeURIComponent(postingId)}`,
  { credentials: "same-origin" },
);
if (!response.ok) throw new Error("This application form is unavailable");
const definition = await response.json();
const sections = definition.application_form.sections;

Render sections in order. Store answers by question ID. Use the types and condition rules in Render application forms. Keep identity fields at the top level, uploaded File objects separately, and explicit consent as a boolean. Use the returned labels as text, never innerHTML.

javascript
// A minimal DOM control for text and single-choice questions.
// Implement the remaining types from the form reference before using a custom flow.
function questionControl(question, onAnswer) {
  const label = document.createElement("label");
  label.textContent = question.label;
  const input = document.createElement(
    question.type === "multiple_choice" ? "select" : "input",
  );
  input.name = question.id;
  input.required = Boolean(question.required);
  if (question.type === "multiple_choice") {
    input.add(new Option("Choose an option", ""));
    for (const option of question.options ?? []) input.add(new Option(option, option));
  } else {
    input.type = ["email", "url", "date", "number"].includes(question.type)
      ? question.type : "text";
  }
  input.addEventListener("change", () => onAnswer(question.id, input.value));
  label.append(input);
  return label;
}

Do not use the minimal control for file, boolean, checkbox-group, education or location questions. Those require their specific answer formats. Reevaluate conditional visibility after answers change, clear hidden answers and validate visible required fields before submission. Use the hosted apply_url if your renderer does not support the returned form.

Submit browser uploads through your server

Send your browser form to your own same-origin server using FormData. Include the identity, custom answers, consent and each selected file. Your server parses this, validates the job/posting against the current form, and runs the following flow. Files below are server-side File objects from your framework's multipart parser; multipart is used between your browser and your server, while calls from your server to Karwa send raw bytes.

javascript
import { KarwaClient } from "./karwa-api-client.mjs";
const client = new KarwaClient();

async function submitFromServer({ jobId, postingId, applicant, files, submissionId }) {
  if (applicant.consent !== true) throw new Error("Consent is required");
  const form = await client.form(jobId, postingId);
  const questions = form.application_form.sections.flatMap(s => s.questions);
  const { token } = await client.session(jobId, postingId);
  const answers = { ...applicant.answers };
  for (const [questionId, file] of Object.entries(files)) {
    const question = questions.find(q => q.id === questionId);
    if (!question || !["resume", "file"].includes(question.type)) {
      throw new Error("Unexpected file question");
    }
    if (!file.size || file.size > form.max_file_bytes) {
      throw new Error("Choose a file within the upload limit");
    }
    const uploaded = await client.upload(
      jobId, postingId, questionId, file.name,
      new Uint8Array(await file.arrayBuffer()), file.type, token,
    );
    answers[questionId] = uploaded.token;
  }
  return client.submit(jobId, postingId, {
    full_name: applicant.full_name,
    email: applicant.email,
    phone: applicant.phone,
    cover_letter: applicant.cover_letter,
    consent: true,
    answers,
  }, token, submissionId);
}

Generate and persist submissionId with your server's applicant session before the first submission. Reuse it on retry. Persist successful upload tokens to avoid reuploading after a submission timeout. Enforce multipart size limits before buffering files, verify same-origin/CSRF protections for your site, rate-limit your public handlers and avoid logging applicant payloads. Return safe validation errors and the receipt to the browser. The function above shows the Karwa calls; your framework's request parser, session storage and abuse controls remain your responsibility.