How to add a salesbillingplan to a sales/salesline through API

Hi,
I’m trying to add a sales with saleslines as a webshop order through API’s. One of the requests of the customer is that the invoice address is changeable per salesline. I tried to implement that by changing the invoice address on the salesbillingplan but I’m getting the error that I’m doing that on a salesbillingplan that doesn’t exist. Is there a standard process that makes a salesbillingplan or can I just create on with the create process?
Also if anyone can explain what a salesbillingplan is exactly, it would be very much appreciated.
Thanks :smiley:

I will try to explain what a salesbillingplan is. A salesbillingplan is a recordtype that connects the sales to the invoices. It is used to determine what goes on an invoice.

A salesbillingplan is connected to a sales and creates billingmoments. It also has salesbillinglines connected. In the datamodelbrowser (you can find using the expression debugger) you’ll find what is connected:
image

The important part for you here is the salesstakeholder and/or the invoiceaddress. From your usecase I get that there are more than one salesstakeholders that can get billed. Or it might be the same stakeholder with different adresses, that would be the invoice adresses field in the salesbillingplan.

When creating a salesline, you also create a connection to the billing_plan and if you select the plan with the correct invoice_address, it would then go on that plan. In creating the invoices, there will be multiple invoices for this sale, both containing part of the saleslines for this sale. The salesbillinglines that are created will connect those (billingmoment, sales_line and sales_billing_plan)

I think the first salesbillingplan is created automatically based on salesstakeholder and invoice_address preferences. Another billing plan needs to be added explicitly either by hand or by process. You can then refer to the correct salesbillingplan when creating saleslines.