As most of you, I guess know, it is not allowed to extend Business Central API’s
This page type cannot be extended by creating a page extension object. Instead, you must create a new API by adding a page object
However, sometimes we just need to send more data about the entity: Customer, Vendor, Sales/Purchase documents etc.
Standard API’s have limited number of fields. For example with /journalLines you can create a line with only 14 field values. However Gen. Journal Line table has more than 100 fields – only in the standard base, not speaking about additional possible table extensions. And usually you find yourself in a situation, when you’ve added some fields to the entity and want to fill them using API, like this guy. And once again we refer to the docs, saying
Instead, you must create a new API by adding a page object
Fair, but to clone the whole page object, just to add 1 field, and then keep it in synch with the next versions for the rest of your life? Not always the best-way-to-go.
What if..
For some of the API’s I found another way. Still limited, but at least something. Let’s return to the journalLines API. Among the allowed-to-fill fields there is one called comment. This is actually a free-text field with the length of 250 symbols
field(5618; Comment; Text[250])
What if we can use this field to pass 3rd party field values, without creating new /journalLines3rdParty API.
Let’s try
Add new fields
I added 3 fields to the General Journal Line

So, I have them in my Business Central

Send values with API
Now, let use /journalLines API and fill the Comment field with Json Token containing my added fields, but in a text format
@commentValue = '{"myBooleanField":true,"myDecimalField":500.5,"myTextField":"someText"}'

Of course in the Business Central we will not get our fields auto-populated 🙂

but, that’s something we can work with.
Parse Comment field
We are going to subscribe to GenJnlLine.OnAfterInsert and parse JsonToken if we are in the ODataV4 session.

Now, after publishing let’s try once again.

The comment field is empty, and we don’t see in the response our fields, but if we look in the Business Central

Limitations
This approach has some limitations.First, you need to find some existing text field, exposed in the standard API. Second this field should have enough length to store additional information. But, if you are lucky you are good to go.
What’s next
I personally use this approach in my custom API’s. I just add a free text variable to the API page (not the table field, but a variable) and then add a publisher to allow 3rd party extensions to parse the value.The example is here

where the ExtraInfoJson is a text

and then in the OnInsert trigger add the ParseExtraText publisher

The rest of the process is the same, as I described in the beginning of the blog. Hope you enjoyed, and safe and happy New Year!