Skip to content

Fix credit note single response parsing - extract credit_note instead of credit_notes#1291

Open
mcse3010 wants to merge 1 commit into
freshbooks:mainfrom
Good-Samaritan-Software-LLC:fix/credit-note-single-response
Open

Fix credit note single response parsing - extract credit_note instead of credit_notes#1291
mcse3010 wants to merge 1 commit into
freshbooks:mainfrom
Good-Samaritan-Software-LLC:fix/credit-note-single-response

Conversation

@mcse3010

Copy link
Copy Markdown
Contributor

Purpose

Fix creditNotes.single(), create(), update(), and delete() methods which were failing with TypeError: Cannot read properties of undefined (reading 'id').

The transformCreditNoteResponse function was extracting credit_notes (plural) from the API response, but the FreshBooks API returns credit_note (singular) for single credit note operations. This is consistent with how other entities work (e.g., invoice not invoices in transformInvoiceResponse).

Before: Methods fail because credit_notes is undefined in the response
After: Methods correctly extract credit_note from the response

Changes

  • Fix CreditNote.ts to extract credit_note instead of credit_notes
  • Update test mocks to match actual API response format

Related Material

See Issue #1290

Don't know if you work on the API docs as well, but -- also interesting to note, the API documentation is wrong and doesn't match what the API returns

  • Documentation with error: https://www.freshbooks.com/api/credits
  • 'Get Single Client' shows a POST instead of a GET and shows the array returning credit_notes (array) instead of a single credit_note.
  • Also there is a formatting inconsistency in 'Create Credit Note' whereas the "POST" isn't colored correctly and the endpoint url example appears below the method name

The transformCreditNoteResponse function was extracting 'credit_notes'
(plural) from the API response, but the FreshBooks API returns 'credit_note'
(singular) for single credit note operations (GET, POST, PUT).

This caused a TypeError when accessing properties on undefined.

Changes:
- Fix CreditNote.ts to extract 'credit_note' instead of 'credit_notes'
- Update test mocks to match actual API response format

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in the credit notes single-entity operations (single(), create(), update(), delete()) that were failing with TypeError: Cannot read properties of undefined (reading 'id'). The root cause was that transformCreditNoteResponse was incorrectly extracting credit_notes (plural) from API responses, when the FreshBooks API actually returns credit_note (singular) for single credit note operations.

Key Changes:

  • Fixed response parsing to use credit_note instead of credit_notes in transformCreditNoteResponse
  • Updated test mocks to match actual API response format for single credit note operations
  • Corrected typo in test description

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/api/src/models/CreditNote.ts Fixed transformCreditNoteResponse to extract credit_note (singular) instead of credit_notes (plural) from API responses, aligning with how other entities (Invoice, Client) handle single-entity responses
packages/api/tests/CreditNote.test.ts Updated mock responses for single(), create(), update(), and delete() tests to use credit_note instead of credit_notes, and fixed typo in test description

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants