Adding expense to invoice via API

I’m trying to add an expense to invoice via API.
Since I couldn’t find any documentation, I tried to read the code but I suck at php.
I came across this however: https://github.com/invoiceninja/invoiceninja/blob/v4.5.49/app/Http/Controllers/ExpenseController.php#L193

        if (in_array($action, ['archive', 'delete', 'restore', 'invoice', 'add_to_invoice'])) {
            return self::bulk();
        }

if I do a PUT request like this

curl -X "PUT" "https://app.invoiceninja.com/api/v1/expenses/1?action=archive"

It archives the expense as expected, so I thought I was in luck and tried action=add_to_invoice and passed in the invoice ID in the body like this:

     -d $'{
  "invoice_id": "92"
}'

but unfortunately I get the message Action [add_to_invoice] is not supported
what am I doing wrong?

ok, found it now.
in BaseAPIController.php this code prevents my action.

        if (! in_array($action, ['archive', 'delete', 'restore', 'mark_sent', 'markSent', 'emailInvoice', 'markPaid'])) {
            return $this->errorResponse("Action [$action] is not supported");
        }

I wonder how the Web UI does it :man_shrugging:t2:

In v4 the web UI bypasses the API, this limits some features from the API.

In v5 the web UI uses the API so all features are available.

ok, this means that there is no way to add expenses to invoices in v4 via API?
That’s not good. Instructed my client to stress your support (hosted paying client) for the v5 issues so I can move them to v5.