
Developer Guide: Sending HIPAA-Compliant Mail Using PostGrid API
For developers building secure healthcare applications, sending documents via mail is still a required function — from EOBs and test results to appointment reminders and ID cards. But when that data qualifies as Protected Health Information (PHI), you need a HIPAA-compliant infrastructure to avoid serious regulatory risk.
This guide will walk you through how to use PostGrid’s secure API to programmatically send mail that complies with the HIPAA Privacy and Security Rules.
Steps Before Sending HIPAA-Compliant Mail via API
Step 1: Sign a Business Associate Agreement (BAA)
Before you can legally transmit PHI through any third-party vendor (including PostGrid), you must sign a Business Associate Agreement (BAA). This is mandated under the HIPAA Omnibus Rule and establishes the legal chain of custody and safeguards.
PostGrid offers a standard HIPAA BAA during onboarding. You’ll receive a downloadable copy to review and sign. Once in place, your account is flagged asHIPAA-enabled, unlocking relevant API parameters and controls.
Step 2: Generate a Secure Bearer API Key
After signing the BAA, navigate to the PostGrid Developer Dashboard to generate your Bearer Token. This key will be required to authenticate all requests to the secure mail API.
⚠️ Important: API keys are environment-specific (sandbox vs live). If you're testing, use your sandbox token to avoid real postage charges.
Authorization: Bearer YOUR_SECURE_API_KEY
Once your BAA is signed and key is provisioned, you’re ready to initiate HIPAA-compliant mailings using the PostGrid API. Let’s explore the key endpoint next.
Endpoint Overview:/print-mailWith HIPAA-Safe Settings
Once your BAA is in place and your API key is ready, you can use PostGrid’s core mailing endpoint:POST /print-mail.
This endpoint allows you to send documents — such as EOBs, test results, appointment letters, or insurance notices — by mail, with options for delivery class, certified mail, and return receipts. To enable HIPAA-specific protections, simply include:
"hipaa": true
Enabling HIPAA Mode
Setting"hipaa": trueactivates enhanced security protocols on PostGrid’s backend:
- Encrypted file storage with short retention
- HIPAA-only print routing (verified facilities)
- Pre-production screening for envelope display violations
- Logging & audit trail at every stage (from upload to USPS handoff)
Basic Payload Structure
Here’s the core structure of a HIPAA-safe request:
{
"to": {
"name": "John Smith",
"addressLine1": "456 Pine Ave",
"city": "Raleigh",
"state": "NC",
"postalCode": "27601"
},
"template_id": "eob_notice_2024",
"hipaa": true,
"certified_true": true,
"metadata": {
"patient_id": "A83924",
"doc_type": "EOB"
}
}
Thecertified_trueflag is optional but highly recommended for high-risk PHI (e.g., HIV status, genetic results, or mental health documents).
All fields accept variable injection using templating logic stored within your PostGrid dashboard templates, enabling personalization at scale.
In the next section, we’ll walk through a full cURL example that sends a HIPAA-safe Certified Mail job.
Sample cURL Request: HIPAA-Safe Certified Mail
For developers testing from the terminal or integrating into CI/CD pipelines, cURL offers a simple way to interact with the PostGrid API. Below is a sample request that securely triggers a HIPAA-compliant Certified Mail job.
curl -X POST "https://api.postgrid.com/print-mail" \
-H "Authorization: Bearer YOUR_SECURE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": {
"name": "John Smith",
"addressLine1": "456 Pine Ave",
"city": "Raleigh",
"state": "NC",
"postalCode": "27601"
},
"template_id": "eob_notice_2024",
"hipaa": true,
"certified_true": true,
"metadata": {
"patient_id": "A83924",
"doc_type": "EOB"
}
}'
What This Request Does:
- Sends an EOB (Explanation of Benefits) document via USPS
- Ensures the document is handled under HIPAA protocols
- Triggers Certified Mail with full delivery confirmation
- Attaches metadata for downstream system reference
Key Tips for Secure Mail Jobs:
- Always double-check
template_idReferences a HIPAA-screened document - Use
certified_truefor high-sensitivity documents like HIV status or behavioral health records - Don’t store PHI in metadata fields — use IDs only
💡 You can monitor job status using the job ID returned in the API response or subscribe to delivery webhooks (we’ll cover that shortly).
Next, we’ll look at how to trigger the same request using JavaScript and Python — two of the most common client integrations for healthcare apps.
📚 Also Read: Document types that trigger mailing compliance
Sample Code: Trigger HIPAA Mail Using JavaScript and Python
Whether you’re building a Node.js backend or a Python-based healthcare app, PostGrid’s REST API makes it easy to integrate mail workflows without compromising HIPAA compliance.
JavaScript (Node.js + Axios)
const axios = require('axios');
const payload = {
to: {
name: "John Smith",
addressLine1: "456 Pine Ave",
city: "Raleigh",
state: "NC",
postalCode: "27601"
},
template_id: "eob_notice_2024",
hipaa: true,
certified_true: true,
metadata: {
patient_id: "A83924",
doc_type: "EOB"
}
};
axios.post('https://api.postgrid.com/print-mail', payload, {
headers: {
'Authorization': 'Bearer YOUR_SECURE_API_KEY',
'Content-Type': 'application/json'
}
})
.then(response => {
console.log("✅ Mail Job Submitted:", response.data.job_id);
})
.catch(error => {
console.error("❌ API Error:", error.response?.data || error.message);
});
Python (Requests Library)
import requests
url = "https://api.postgrid.com/print-mail"
headers = {
"Authorization": "Bearer YOUR_SECURE_API_KEY",
"Content-Type": "application/json"
}
payload = {
"to": {
"name": "John Smith",
"addressLine1": "456 Pine Ave",
"city": "Raleigh",
"state": "NC",
"postalCode": "27601"
},
"template_id": "eob_notice_2024",
"hipaa": True,
"certified_true": True,
"metadata": {
"patient_id": "A83924",
"doc_type": "EOB"
}
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
print("✅ Mail Job Submitted:", response.json().get("job_id"))
else:
print("❌ API Error:", response.text)
Notes:
- All mail jobs return a
job_id— Store this for tracking or reconciliation - You can poll status or use webhooks to get delivery updates
- All secure traffic should be TLS 1.3+ with an HTTPS endpoint
Next, we’ll walk through setting up delivery event webhooks — so you know when a document is printed, mailed, and delivered.
Webhooks for Delivery Status Tracking
When sending HIPAA-sensitive mail, visibility doesn’t end with submission — you need a full audit trail of delivery status, handoff timestamps, and mailpiece outcomes.
PostGrid provides secure webhooks that notify your system in real time when:
- A job is submitted and accepted
- A document is printed and packaged
- USPS picks up the mailpiece
- Final delivery or Certified Mail signature is confirmed
🔧 How to Set Up Webhooks
- Log in to your PostGrid Developer Portal
- Go to
Webhooks → Add Endpoint - Enter your webhook URL (must support HTTPS)
- Select HIPAA-safe events (e.g.,
job.updated,delivery.confirmed) - PostGrid signs each payload with a secret token
Example Webhook Payload:
{
"event": "delivery.confirmed",
"job_id": "abc_12345",
"status": "delivered",
"timestamp": "2025-06-27T15:42:00Z",
"metadata": {
"patient_id": "A83924",
"doc_type": "EOB"
}
}
HIPAA-Safe Tips:
- Use HTTPS + HMAC signature validation
- Log webhook events in your compliance audit trail
- Never return PHI in webhook responses
💡 Pro Tip: Webhooks allow your systems to react in real time — update dashboards, alert support staff, or log delivery confirmations for OCR audits.
Next, we’ll show how to test all of this securely in sandbox mode before launching live mailings.
Testing in Sandbox Mode (No Live Postage)
Before you send a single mailpiece through live USPS channels, PostGrid provides a fully functional Sandbox Environment that mimics the production API, without generating any real mail or postage charges.
Why Use Sandbox?
- Validate API structure and payload schema
- Preview templates and rendering logic
- Confirm HIPAA-related logic works as expected
- Catch potential PHI display violations before production
Sandbox Base URL:
https://sandbox.postgrid.com/print-mail
Example Test Request
curl -X POST "https://sandbox.postgrid.com/print-mail" \
-H "Authorization: Bearer YOUR_SANDBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": {
"name": "Test Patient",
"addressLine1": "123 Sandbox Lane",
"city": "Faketown",
"state": "CA",
"postalCode": "99999"
},
"template_id": "test_template",
"hipaa": true,
"certified_true": false,
"metadata": {
"test_case": "PHI alignment"
}
}'
What You’ll Receive:
- Simulated job ID and status logs
- Rendered PDF preview of mailpiece
- Metadata echo in response for test tracking
- Validation flags if content violates envelope constraints
Best Practices for HIPAA-Safe Testing:
- Don’t use real patient data — use test payloads only
- Keep sandbox keys separate from prod keys
- Use
"hipaa": trueduring testing to preview security routing
💡 Reminder: Nothing you send in Sandbox Mode is ever mailed — it’s a full simulation environment for rendering, timing, and error testing.
Up next: Let’s review common API errors and how to handle them in production systems.
Error Handling: Common API Issues & Fixes
Even in HIPAA-secure systems, developers must anticipate and handle errors gracefully, especially when PHI is involved. Below is a table of the most common HTTP response codes returned by PostGrid’s API and how to address them:
| Status Code | Meaning | Possible Fix |
|---|---|---|
| 400 Bad Request | Missing or malformed payload fields | Check JSON syntax; validate required fields liketo,template_id |
| 401 Unauthorized | Invalid or missing Bearer token | Use correct token for sandbox or production; check BAA status |
| 403 Forbidden | Trying to use HIPAA or Certified Mail without permissions | Ensure BAA is signed; your API key must be HIPAA-enabled |
| 404 Not Found | Incorrect endpoint or invalidtemplate_id |
Double-check your endpoint URL and template name |
| 422 Unprocessable Entity | Validation error — envelope display issue or template logic | Ensure no PHI is exposed in window zone; contact support |
| 500 Server Error | PostGrid internal issue | Retry with backoff or open a support ticket |
💡Pro Tip: Use Status Codes + Job Logs
Every failed job returns a JSON response with a human-readable message and job_idfor traceability. Log these for your compliance records or trigger custom alerts in your app.
With robust error handling in place, your HIPAA-safe mail system can now be considered audit-ready. Let’s close with a final call to action for developers to begin securely.
Start Sending HIPAA-Compliant Mail via API
Whether you're building a patient portal, automating EOBs, or sending prescription reminders, PostGrid lets your development team trigger fully HIPAA-compliant mail in seconds, without the overhead of print/mail infrastructure or legal guesswork.
Your Next Steps:
- Sign your BAA — required to activate HIPAA mode
- Get your API keys (sandbox & live)
- Use
"hipaa": trueand optional"certified_true"to secure mail traffic - Set up delivery webhooks for real-time status updates
Reminder: PostGrid’s HIPAA-ready platform supports:
- ✅ Secure Certified Mail workflows
- ✅ SOC 2 audited infrastructure
- ✅ Role-based access + activity logs
- ✅ 14-day encrypted document retention
Build HIPAA compliance into your codebase — not as an afterthought, but as a foundation.

