Payerworks writes and explains files; it sends nothing to a payer. Every file a route writes says transmitted: false, and is yours to send on your own connection. A test key is for invented data only, never a real patient.
What you need
- A test key, from the developers page. It is for invented data only.
- Node 18 or later, the JavaScript client payerworks.mjs, and sample-data.mjs, the invented patient and clinic every example uses, in one folder.
- Two environment variables:
PAYERWORKS_API_KEY(your key) andPAYERWORKS_BASE_URL(the base URL shown with your key).
The steps
- 1. Announce the attachment on the claim: a report type, the transmission code EL (sent electronically) and a control number, in
claimInformation.claimSupplementalInformation.reportInformations. - 2. Check the claim with POST /v1/claims/validate. It is valid, and it carries the warning
pwk_el_needs_attachment: the payer will wait for a 275 under that control number. - 3. Write the attachment with POST /v1/attachments/275 under the same control number: each file base64 in its own segment, with its LOINC document type when you give one. The payer matches the two by that number.
- 4. Read the answer’s
shape: the 275 is written as public payer companion guides show it, not from the licensed implementation guide. Check your payer’s own guide before you send it.
The code
attachment-275.mjs runs every step below against the API with a test key. It needs payerworks.mjs and sample-data.mjs beside it.
// Payerworks example: a claim attachment as an X12 275. Docs: https://payerworks.com/docs/quickstart-first-275
//
// Run it with Node 18 or later, with the JavaScript client (https://payerworks.com/sdk/payerworks.mjs)
// and sample-data.mjs beside this file:
// PAYERWORKS_API_KEY=pw_test_... PAYERWORKS_BASE_URL=<the base URL shown with your key> node attachment-275.mjs
// A test key and invented data only. Payerworks sends nothing to a payer: every file it writes is yours.
import { pathToFileURL } from 'node:url';
import { Payerworks, PayerworksError } from './payerworks.mjs';
import { CLAIM, SENDER_ID, PAYER_ID, copy, refusalOf } from './sample-data.mjs';
/** The control number the claim announces and the 275 carries: the payer matches the two by it. */
const ATTACHMENT = 'EXATT0001';
/** @param {Payerworks} pw */
export async function run(pw) {
// 1. The claim announces its attachment: report type 09 (a progress report), sent electronically (EL), under ATTACHMENT.
const claim = copy(CLAIM);
claim.claimInformation.claimSupplementalInformation = { reportInformations: [{ attachmentReportTypeCode: '09', attachmentTransmissionCode: 'EL', attachmentControlNumber: ATTACHMENT }] };
const checked = await pw.postClaimsValidate({ claim });
// 2. The attachment itself, as a 275 under the same control number. An invented one-page PDF here.
const file = Buffer.from('%PDF-1.4\n% an invented progress note\n1 0 obj<<>>endobj\ntrailer<<>>\n%%EOF\n').toString('base64');
const written = await pw.postAttachments275({
sender_id: SENDER_ID, receiver_id: PAYER_ID, control_number: 7, claim,
attachments: [{ control_number: ATTACHMENT, content_type: 'application/pdf', content_base64: file, filename: 'progress note.pdf', loinc: '11506-3' }],
});
// 3. The failure path: a control number the claim does not announce is refused, so the payer is never sent an attachment it cannot match.
const refused = await refusalOf(() => pw.postAttachments275({
sender_id: SENDER_ID, receiver_id: PAYER_ID, control_number: 8, claim,
attachments: [{ control_number: 'EXATT0002', content_type: 'application/pdf', content_base64: file, filename: 'other.pdf' }],
}), { PayerworksError });
return {
claim_valid: checked.valid,
warnings: checked.claims[0].warnings.map((w) => w.code),
written: { transmitted: written.transmitted, has_trn: written.x12.includes(`TRN*1*${ATTACHMENT}`), shape_verified: written.shape?.verified },
refused,
};
}
// Run as a script: node <this file>, with PAYERWORKS_API_KEY and PAYERWORKS_BASE_URL set.
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
console.log(JSON.stringify(await run(new Payerworks()), null, 2));
}
{
"claim_valid": true,
"warnings": [
"pwk_el_needs_attachment"
],
"written": {
"transmitted": false,
"has_trn": true,
"shape_verified": false
},
"refused": {
"status": 422,
"code": "invalid_attachments",
"request_id": "req_3"
}
}What you should see
warningsis the reminder that a 275 must follow;has_trnsays the 275 carries the claim’s control number;refusedis a control number the claim never announced.
Next
- The other documents (the CMS-1500, the remittance and eligibility PDFs, Medicare’s appeal forms) are on Documents and attachments.