I need to call third party APIs where the payload size has a maximum size limit, say, 4 MB. That means I cannot call the API with a payload more than 4MB in size.
How can I solve this in an algorithmic way? Because a simple solution could be like every time I generate a payload, I check the size, and if it exceeds, I can regenerate it. But this is not an effective solution and not good from a performance point of view.
For more detail, let's take this example. There is one API where I can file invoices in one call only. Now I can have thousands of invoices and each invoice could have different data as per business.
In this, how can I determine a benchmark to send a limited number of invoices to meet the size limit requirement?