# HubSpot Custom Code: Invoice creation returns “Invalid request” even though execution is successful

**URL:** <https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [January 16, 2026, 8:56pm UTC](https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049 "2026-01-16T20:56:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RBerou](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@RBerou](https://community.hubspot.com/u/RBerou)\
**Post date:** [January 16, 2026, 8:56pm UTC](https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049/1 "2026-01-16T20:56:29Z")

</div>

Hi everyone,

I’m trying to automatically create an **invoice from a deal’s line items when the deal is moved to Closed Won, using a Deal-based workflow with a Custom Code (Node.js) action.**

### What I’m trying to achieve

- Trigger: Deal moves to **Closed Won**

- Action: Create an **invoice**

- Copy the **deal’s line items onto the invoice**

- Use HubSpot’s CRM APIs inside a workflow custom code action

---

<div class="post-metadata">

**Author:** ![DaganBPM](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/daganbpm/32/88723_2.png) [@DaganBPM](https://community.hubspot.com/u/DaganBPM)\
**Post date:** [January 16, 2026, 10:16pm UTC](https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049/2 "2026-01-16T22:16:52Z")

</div>

You can likely see more detailed logs under the Private App token you’re using, if you go back to where you copied the token from and look for the tab that says **Logs,** then look for a failed call and click on it. If you paste the logs here I’d be happy to take a closer look, I’ve spent my fair share of time debugging API issues with my own workflows haha

---

<div class="post-metadata">

**Author:** ![RBerou](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@RBerou](https://community.hubspot.com/u/RBerou)\
**Post date:** [January 17, 2026, 2:29am UTC](https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049/3 "2026-01-17T02:29:03Z")

</div>

As I check the log to my private app, it is not showing anything, maybe I set it up wrong that it is not receiving the API calls?

---

<div class="post-metadata">

**Author:** ![DaganBPM](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/daganbpm/32/88723_2.png) [@DaganBPM](https://community.hubspot.com/u/DaganBPM)\
**Post date:** [January 18, 2026, 2:04pm UTC](https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049/4 "2026-01-18T14:04:09Z")

</div>

Apologies for the delay in replying, I’ve tried to replicate the error but been unable to, the code in that Github gist is working in my test account. One suggestion to try and see more detailed logs:

- Open your workflow and click on the Custom Code Action
- Scroll to the bottom of the action until you see ‘Test Action’

 ![DaganBPM_1-1768745012924.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/6/6cc0bb4bd86197b7d45af92556598be59c633b3d.png)

- Click on it, select a Deal, and hit ‘Test’
- Scroll down a little more and look for the logs there, does anything show up there other than `Invalid request`?

Have you confirmed that your Access Token has all the required scopes used in the script?

Let me know on the above and happy to keep digging into this!

---

<div class="post-metadata">

**Author:** ![RBerou](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@RBerou](https://community.hubspot.com/u/RBerou)\
**Post date:** [January 19, 2026, 8:44am UTC](https://community.hubspot.com/t/hubspot-custom-code-invoice-creation-returns-invalid-request-even-though-execution-is-successful/145049/5 "2026-01-19T08:44:00Z")

</div>

Thank you for the help, for no reason it is working now.
