Process a credit note and rebill charges
The credit note + rebilling flow lets you reissue charges that were already invoiced — for example when the payer rejects an invoice, an agreement changes, or a billing error is discovered. It is a two-step process: first you apply the credit note, then you rebill the released charges to a new invoice.
By the end of this guide you will have:
- Marked the original invoice's account as
NON_PROCESSABLEand released its charges. - Assigned those charges to a new invoice via the async rebilling endpoint.
- Polled for the rebilling result and confirmed per-charge status.
Prerequisites
- 1An access token
OAuth2 client credentials grant — see Obtaining tokens. Your client must have the
ASSIGN_CHARGE_TO_INVOICEauthority. - 2An existing invoiced account
The account must have an invoice in
ASSIGNEDstatus with active charges, a payer, and at least one enabled event. - 3A new invoice number ready
The rebilling step requires a fresh
invoice_numberthat hasn't been used before. Your billing system should generate this.
Step 1 — Apply the credit note
Endpoint
POST /v1/invoices/credit-note
Content-Type: application/json
Authorization: Bearer <token>
Request
| Field | Required | Description |
|---|---|---|
invoice_number | yes | The invoice number of the account to credit-note. Must be in ASSIGNED status. |
Response (200 OK)
| Field | Description |
|---|---|
account_id | UUID of the affected account. |
invoice_number | The invoice that was credit-noted. |
previous_status | Account status before the operation. |
current_status | Always NON_PROCESSABLE on success. |
charges_released | Number of charges that were disabled and released. |
probable_for_refund | true — the account is flagged for potential refund processing. |
message | Human-readable confirmation message. |
Walkthrough
1. curl
curl -X POST https://sandbox.osigu.com/rcm/v1/invoices/credit-note \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"invoice_number": "INV-2024-001"
}'
Response:
{
"account_id": "a1b2c3d4-5678-90ab-cdef-1234567890ab",
"invoice_number": "INV-2024-001",
"previous_status": "OPEN",
"current_status": "NON_PROCESSABLE",
"charges_released": 3,
"probable_for_refund": true,
"message": "Credit note processed successfully"
}
2. Node.js
async function processCreditNote(token, invoiceNumber) {
const res = await fetch('https://sandbox.osigu.com/rcm/v1/invoices/credit-note', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ invoice_number: invoiceNumber }),
});
if (!res.ok) {
const error = await res.json();
throw new Error(`Credit note failed: ${res.status} — ${error.message}`);
}
return res.json();
}
const result = await processCreditNote(token, 'INV-2024-001');
console.log(`Released ${result.charges_released} charges, account is now ${result.current_status}`);
3. Python
import requests
def process_credit_note(token, invoice_number):
r = requests.post(
'https://sandbox.osigu.com/rcm/v1/invoices/credit-note',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json',
},
json={'invoice_number': invoice_number},
timeout=30,
)
r.raise_for_status()
return r.json()
result = process_credit_note(token, 'INV-2024-001')
print(f"Released {result['charges_released']} charges")
4. Java (Spring RestClient)
import org.springframework.http.MediaType;
import org.springframework.web.client.RestClient;
import java.util.Map;
public Map<String, Object> processCreditNote(RestClient client, String token, String invoiceNumber) {
return client.post()
.uri("https://sandbox.osigu.com/rcm/v1/invoices/credit-note")
.header("Authorization", "Bearer " + token)
.contentType(MediaType.APPLICATION_JSON)
.body(Map.of("invoice_number", invoiceNumber))
.retrieve()
.body(Map.class);
}
Step 2 — Rebill charges to a new invoice
Once the credit note is applied and the charges are released, assign them to a new invoice.
Endpoint
POST /v1/invoices/rebilling
Content-Type: application/json
Authorization: Bearer <token>
Request
| Field | Required | Description |
|---|---|---|
agreement_code | yes | The provider-payer agreement for the new invoice. |
invoice_number | yes | A new, unused invoice number for the rebilled charges. |
source_invoice_number | yes | The original invoice that was credit-noted in Step 1. |
charge_codes | yes | Array of charge codes to reassign. These must be released (invoiceAssigned = false). |
settlement_number | no | Payer's settlement number, when applicable. |
batch_number | no | Batch grouping identifier, when applicable. |
Response (202 Accepted)
No body. The Location header contains the status URL:
Location: /rcm/v1/invoices/rebilling/status/f47ac10b-58cc-4372-a567-0e02b2c3d479
Walkthrough
1. curl
# Start the rebilling
curl -i -X POST https://sandbox.osigu.com/rcm/v1/invoices/rebilling \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"agreement_code": "AGREEMENT_001",
"invoice_number": "NEW-INV-2024-002",
"source_invoice_number": "INV-2024-001",
"charge_codes": ["CHG-001", "CHG-002", "CHG-003"]
}'
# Response headers include:
# HTTP/1.1 202 Accepted
# Location: /rcm/v1/invoices/rebilling/status/f47ac10b-...
# Poll for status
curl https://sandbox.osigu.com/rcm/v1/invoices/rebilling/status/f47ac10b-58cc-4372-a567-0e02b2c3d479 \
-H "Authorization: Bearer $TOKEN"
Status response:
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"invoice_number": "NEW-INV-2024-002",
"agreement_code": "AGREEMENT_001",
"total_charges_processed": 3,
"status": "COMPLETED",
"charges": [
{ "code": "CHG-001", "status": "COMPLETED", "error_description": null },
{ "code": "CHG-002", "status": "COMPLETED", "error_description": null },
{ "code": "CHG-003", "status": "COMPLETED", "error_description": null }
]
}
2. Node.js
async function rebillCharges(token, { agreementCode, invoiceNumber, sourceInvoiceNumber, chargeCodes }) {
const res = await fetch('https://sandbox.osigu.com/rcm/v1/invoices/rebilling', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
agreement_code: agreementCode,
invoice_number: invoiceNumber,
source_invoice_number: sourceInvoiceNumber,
charge_codes: chargeCodes,
}),
});
if (res.status !== 202) {
const error = await res.json();
throw new Error(`Rebilling failed: ${res.status} — ${error.message}`);
}
// Extract the status URL from the Location header
const statusUrl = res.headers.get('Location');
return statusUrl;
}
async function pollRebillingStatus(token, statusUrl, maxAttempts = 20) {
for (let i = 0; i < maxAttempts; i++) {
const res = await fetch(`https://sandbox.osigu.com${statusUrl}`, {
headers: { 'Authorization': `Bearer ${token}` },
});
const status = await res.json();
if (status.status === 'COMPLETED' || status.charges.some(c => c.status === 'ERROR')) {
return status;
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
throw new Error('Rebilling timed out');
}
// Usage
const statusUrl = await rebillCharges(token, {
agreementCode: 'AGREEMENT_001',
invoiceNumber: 'NEW-INV-2024-002',
sourceInvoiceNumber: 'INV-2024-001',
chargeCodes: ['CHG-001', 'CHG-002', 'CHG-003'],
});
const result = await pollRebillingStatus(token, statusUrl);
console.log(`Rebilling ${result.status}: ${result.total_charges_processed} charges processed`);
3. Python
import time
import requests
def rebill_charges(token, agreement_code, invoice_number, source_invoice_number, charge_codes):
r = requests.post(
'https://sandbox.osigu.com/rcm/v1/invoices/rebilling',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json',
},
json={
'agreement_code': agreement_code,
'invoice_number': invoice_number,
'source_invoice_number': source_invoice_number,
'charge_codes': charge_codes,
},
timeout=30,
)
r.raise_for_status()
return r.headers['Location']
def poll_rebilling_status(token, status_url, max_attempts=20):
for _ in range(max_attempts):
r = requests.get(
f'https://sandbox.osigu.com{status_url}',
headers={'Authorization': f'Bearer {token}'},
timeout=30,
)
r.raise_for_status()
status = r.json()
if status['status'] == 'COMPLETED' or any(c['status'] == 'ERROR' for c in status['charges']):
return status
time.sleep(2)
raise TimeoutError('Rebilling did not complete in time')
# Usage
status_url = rebill_charges(
token,
agreement_code='AGREEMENT_001',
invoice_number='NEW-INV-2024-002',
source_invoice_number='INV-2024-001',
charge_codes=['CHG-001', 'CHG-002', 'CHG-003'],
)
result = poll_rebilling_status(token, status_url)
print(f"Rebilling {result['status']}: {result['total_charges_processed']} charges processed")
4. Java (Spring RestClient)
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClient;
import java.net.URI;
import java.util.List;
import java.util.Map;
public URI startRebilling(RestClient client, String token,
String agreementCode, String invoiceNumber,
String sourceInvoiceNumber, List<String> chargeCodes) {
ResponseEntity<Void> response = client.post()
.uri("https://sandbox.osigu.com/rcm/v1/invoices/rebilling")
.header("Authorization", "Bearer " + token)
.contentType(MediaType.APPLICATION_JSON)
.body(Map.of(
"agreement_code", agreementCode,
"invoice_number", invoiceNumber,
"source_invoice_number", sourceInvoiceNumber,
"charge_codes", chargeCodes
))
.retrieve()
.toBodilessEntity();
return response.getHeaders().getLocation();
}
public Map<String, Object> pollRebillingStatus(RestClient client, String token, URI statusUri)
throws InterruptedException {
for (int i = 0; i < 20; i++) {
Map<String, Object> status = client.get()
.uri("https://sandbox.osigu.com" + statusUri.getPath())
.header("Authorization", "Bearer " + token)
.retrieve()
.body(Map.class);
if ("COMPLETED".equals(status.get("status"))) {
return status;
}
Thread.sleep(2000);
}
throw new RuntimeException("Rebilling did not complete in time");
}
Full flow example
Here is the complete two-step flow using curl:
# Step 1: Apply credit note
echo "=== Step 1: Credit note ==="
curl -s -X POST https://sandbox.osigu.com/rcm/v1/invoices/credit-note \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"invoice_number": "INV-2024-001"}' | jq .
# Step 2: Rebill to new invoice
echo "=== Step 2: Start rebilling ==="
LOCATION=$(curl -s -i -X POST https://sandbox.osigu.com/rcm/v1/invoices/rebilling \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"agreement_code": "AGREEMENT_001",
"invoice_number": "NEW-INV-2024-002",
"source_invoice_number": "INV-2024-001",
"charge_codes": ["CHG-001", "CHG-002", "CHG-003"]
}' | grep -i "^Location:" | tr -d '\r' | cut -d' ' -f2)
echo "Status URL: $LOCATION"
# Step 3: Poll until done
echo "=== Step 3: Poll status ==="
while true; do
STATUS=$(curl -s "https://sandbox.osigu.com${LOCATION}" \
-H "Authorization: Bearer $TOKEN")
echo "$STATUS" | jq .status
if echo "$STATUS" | jq -e '.status == "COMPLETED"' > /dev/null 2>&1; then
echo "$STATUS" | jq .
break
fi
sleep 2
done
What happens next
After a successful rebilling:
- A new invoiced account is created with the reassigned charges, support files, and invoice — identical to the standard assign-charges flow.
- The new account is marked as reassigned (
reassigned_account = true,reassigned_account_idpointing to the original account) for audit traceability. - The original account remains
NON_PROCESSABLE— this is a terminal state. It is not voided. - Support files are carried over — you do not need to re-upload them.
From here, the new invoice follows the standard billing cycle: it can be grouped into a pre-settlement and dispatched to the payer.
Common errors
Credit note errors
| Status | Error | What went wrong | Fix |
|---|---|---|---|
404 | invoice-not-found | Invoice doesn't exist, isn't ASSIGNED, or is disabled. | Verify the invoice_number and that the invoice is in ASSIGNED status. |
422 | account-disabled | The underlying account is disabled. | The account was soft-deleted. This cannot be credit-noted. |
422 | already-non-processable | Account was already credit-noted. | No action needed — the credit note was already applied. Proceed to rebilling. |
422 | no-charges | No active charges on the account. | The account has no billable items to release. |
422 | no-payer | No payer assigned. | Assign a payer to the account before applying the credit note. |
422 | no-services | No enabled events. | The account has no clinical encounters. |
Rebilling errors
| Status | Error | What went wrong | Fix |
|---|---|---|---|
404 | source-invoice-not-found | Source invoice doesn't exist or isn't ASSIGNED. | Verify the source_invoice_number. |
422 | account-not-non-processable | The credit note hasn't been applied yet. | Apply the credit note first (Step 1), then retry. |
422 | source-account-disabled | Source account is disabled. | This account cannot be rebilled. |
422 | charges-not-found | One or more charge codes don't exist. | Verify the charge codes belong to the provider. |
422 | charges-not-available | Charges still have invoiceAssigned = true. | The credit note didn't release these charges. Verify the source invoice number matches. |
Edge cases
- Partial rebilling. You don't have to rebill all released charges at once. You can rebill a subset and leave the rest for a later rebilling call (or not at all).
- Different agreement on rebilling. The
agreement_codein the rebilling request can differ from the original. This is how payer-change rebilling works — the payer change happens before calling rebilling. - Duplicate rebilling request. If you POST the same charge codes again, the endpoint returns the existing assignment (idempotent via charge code hash). You get back the same status URL.
- Mixed charge outcomes. When polling status, individual charges may succeed or fail independently. A charge that fails (e.g., code conflict) shows
status: "ERROR"with anerror_description. Other charges in the same request are not affected. - No automatic rollback. If rebilling fails for some charges, the credit note is not reversed. The original account stays
NON_PROCESSABLE. Fix the failing charges and retry the rebilling with the corrected codes.