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

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


    What I followed

    I followed this YouTube tutorial step by step:
    https://www.youtube.com/watch?v=uG5mT2kiRqg

    The video references this GitHub Gist for the code:
    Generate an invoice with HubSpot's APIs · GitHub

    I implemented everything exactly as shown in the video.


    My setup

    • Deal-based workflow

    • Trigger: Deal stage = Closed Won

    • Custom code action (Node.js)

    • Private App access token stored as a Secret

    • hs_object_id (Deal ID) added under Properties to include in code

    • Token is read via process.env.Token


      What happens

      • The custom code action executes successfully

      • Workflow shows Status: Success

      • However, the logs show this error:

          2026-01-16T20:51:06.410Z ERROR Invalid request
        
          ` `
        
          There’s no additional detail returned in the log about which request is invalid.
        
          ---
        
          ### My question
        
          Has anyone:
        
        • Successfully used this exact approach recently?

        • Run into “Invalid request” errors when creating invoices via custom code?

        • Noticed changes or limitations with the Invoices object or required properties?

                  Any guidance on:
          
          • Required invoice properties

          • Account limitations for invoices

          • Or debugging this “Invalid request” error inside workflows

                            would be greatly appreciated.
            
                            Thanks in advance!
            

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

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?

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’

  • 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!

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