Hi Osvaldo,
Thanks for your suggestion.

The CreateInvoice API is analogous to creating an invoice via the admin UI. These one-time standalone invoices aren't related to services.
To generate an invoice related to a service, use the GenInvoices API instead: https://developers.whmcs.com/api-reference/geninvoices/