Node.js5 min5 steps
Generate a SOAP Note with Node.js
Use the built-in fetch API to generate a structured SOAP note with zero dependencies.
1
Set your API key
Export your API key as an environment variable. Node.js 18+ reads it from
process.env. You can find your key in the dashboard.Terminal
export SOAPNOTEAPI_KEY="snapi_sk_test_your_key_here"2
Make the request
Node.js 18+ includes the Fetch API globally, so no packages are needed. Send a POST request to
/v1/note with your clinical transcript.JavaScript
const apiKey = process.env.SOAPNOTEAPI_KEY;
const response = await fetch("https://api.soapnoteapi.com/v1/note", {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
transcript:
"Patient is a 62-year-old female presenting for annual wellness visit. " +
"She reports well-controlled type 2 diabetes on metformin 1000mg BID. " +
"A1C last month was 6.8%. Denies polyuria, polydipsia, or blurred vision. " +
"Vitals: BP 132/78, HR 68, BMI 27.4. Foot exam normal, monofilament intact. " +
"Assessment: type 2 diabetes mellitus, well controlled. " +
"Plan: continue metformin, repeat A1C in 6 months, annual eye exam referral.",
specialty: "physician",
}),
});
const note = await response.json();
console.log(note);3
Parse the response
The response includes each SOAP section as a separate field. Here is a TypeScript interface describing the shape of the response.
JavaScript
interface SOAPNoteResponse {
noteId: string;
status: "completed" | "processing" | "failed";
specialty: string;
subjective: string;
objective: string;
assessment: string;
plan: string;
created_at: string;
}
// Access each section
console.log("Subjective:", note.subjective);
console.log("Objective:", note.objective);
console.log("Assessment:", note.assessment);
console.log("Plan:", note.plan);4
Handle errors
Always check
response.ok before parsing the body. The API returns JSON error objects for all failure cases.JavaScript
async function generateNote(transcript: string, specialty: string) {
const response = await fetch("https://api.soapnoteapi.com/v1/note", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SOAPNOTEAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ transcript, specialty }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({ message: "Unknown error" }));
switch (response.status) {
case 401:
throw new Error("Invalid API key. Check your SOAPNOTEAPI_KEY variable.");
case 400:
throw new Error(`Validation error: ${error.message}`);
case 429:
throw new Error("Rate limited. Wait and retry.");
default:
throw new Error(`API error (${response.status}): ${error.message}`);
}
}
return response.json();
}5
Complete runnable script
Save this as
generate-note.mjs and run it with node generate-note.mjs. Set your SOAPNOTEAPI_KEY environment variable first.JavaScript
#!/usr/bin/env node
// generate-note.mjs — Generate a SOAP note from a clinical transcript
const API_URL = "https://api.soapnoteapi.com/v1/note";
async function generateNote(transcript, specialty = "physician") {
const apiKey = process.env.SOAPNOTEAPI_KEY;
if (!apiKey) {
console.error("Error: set the SOAPNOTEAPI_KEY environment variable.");
process.exit(1);
}
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ transcript, specialty }),
});
if (!response.ok) {
const error = await response.json().catch(() => ({}));
console.error(`Error (${response.status}): ${error.message ?? response.statusText}`);
process.exit(1);
}
return response.json();
}
const transcript =
"Patient is a 62-year-old female presenting for annual wellness visit. " +
"She reports well-controlled type 2 diabetes on metformin 1000mg BID. " +
"A1C last month was 6.8%. Denies polyuria, polydipsia, or blurred vision. " +
"Vitals: BP 132/78, HR 68, BMI 27.4. Foot exam normal, monofilament intact. " +
"Assessment: type 2 diabetes mellitus, well controlled. " +
"Plan: continue metformin, repeat A1C in 6 months, annual eye exam referral.";
const note = await generateNote(transcript);
for (const section of ["subjective", "objective", "assessment", "plan"]) {
console.log(`\n--- ${section.toUpperCase()} ---`);
console.log(note[section]);
}Ready to start building?
Get a free API key and $10 in credit — no credit card required.
Get your free API keyNext steps
Multiple10 min
Upload Audio and Get a SOAP Note
Upload an audio recording of a clinical encounter and receive a transcribed, structured SOAP note.
Multiple10 min
Stream SOAP Notes with SSE
Enable Server-Sent Events to display each SOAP section as it is generated, delivering a real-time experience.
Multiple5 min
Add Billing Codes to SOAP Notes
Include ICD-10 and CPT codes alongside your SOAP note to streamline clinical billing workflows.