Bug Description
The creditNotes.single() method fails with TypeError: Cannot read properties of undefined (reading 'id') because transformCreditNoteResponse extracts the wrong key from the API response.
Root Cause
In packages/api/src/models/CreditNote.ts:133, the code extracts credit_notes (plural):
const { credit_notes } = response.response.result
return transformCreditNoteParsedResponse(credit_notes)
But the FreshBooks API returns credit_note (singular) for single-record operations:
{
"response": {
"result": {
"credit_note": { ... }
}
}
}
This is inconsistent with how other entities handle this correctly. For example, Invoices.ts:144:
const { invoice } = response.response.result // singular - correct
Steps to Reproduce
const client = new Client(clientId, { accessToken: token }) const { data } = await client.creditNotes.single(accountId, creditId) // TypeError: Cannot read properties of undefined (reading 'id')
Expected Behavior
Should return the credit note object successfully.
Actual Behavior
Throws TypeError: Cannot read properties of undefined (reading 'id') because credit_notes is undefined (API returns credit_note).
Affected Operations
All operations using transformCreditNoteResponse:
- creditNotes.single() (GET)
- creditNotes.create() (POST)
- creditNotes.update() (PUT)
- creditNotes.delete() (PUT with vis_state)
Proposed Fix
- const { credit_notes } = response.response.result
- const { credit_note } = response.response.result
- return transformCreditNoteParsedResponse(credit_notes)
- return transformCreditNoteParsedResponse(credit_note)
Environment
- SDK Version: 4.1.0
- Node.js: 18+
Bug Description
The creditNotes.single() method fails with TypeError: Cannot read properties of undefined (reading 'id') because transformCreditNoteResponse extracts the wrong key from the API response.
Root Cause
In packages/api/src/models/CreditNote.ts:133, the code extracts credit_notes (plural):
const { credit_notes } = response.response.result
return transformCreditNoteParsedResponse(credit_notes)
But the FreshBooks API returns credit_note (singular) for single-record operations:
{
"response": {
"result": {
"credit_note": { ... }
}
}
}
This is inconsistent with how other entities handle this correctly. For example, Invoices.ts:144:
const { invoice } = response.response.result // singular - correct
Steps to Reproduce
const client = new Client(clientId, { accessToken: token }) const { data } = await client.creditNotes.single(accountId, creditId) // TypeError: Cannot read properties of undefined (reading 'id')Expected Behavior
Should return the credit note object successfully.
Actual Behavior
Throws TypeError: Cannot read properties of undefined (reading 'id') because credit_notes is undefined (API returns credit_note).
Affected Operations
All operations using transformCreditNoteResponse:
Proposed Fix
Environment