web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

Perform action after API request

(0) ShareShare
ReportReport
Posted on by 5

Hello, 

Is it possible to call functions after API request?

My case: 

I prepared API page for Business Central and now I need to call function after the call is send. I tired to use triggers: OnClosePage, OnQueryClosePage but those two are not working. Is there any other possibility to call function after API request in BC?

I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    You can define actions in your API. There are a lots of blogs around this.

    Maybe this will be at help:

    www.kauffmann.nl/.../

  • DevPl320 Profile Picture
    5 on at

    Thanks for reply.

    I know how to call service enabled action from api, but what I was looking for is different scenario.

    There is POST Api call and i want to perform action right after this call, without having to call another procedure using other call.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    All your table triggers and integration events should run. So if you insert something through your API the OnInsert trigger on the table should run or any event triggers connected to that.

  • DevPl320 Profile Picture
    5 on at

    Thanks. I have one more case. There is API Page- 'Doc Header' and this page contains part with other API -'Doc Lines'. What I want to achieve is to call post function right after inserting last line. So order is like:

    1.Insert Header

    2.Insert Lines

    3.Call Post Action.

    Is it possible to call posting right after POST request or I have to prepare ServiceEnabled function, like You mentioned before, which will perform posting action?

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    It is possible but i would not do it that way.

    What i would do is to create a time trigger job in the job queue that every x minutes looks for new records in doc header and then post them. This is because than a failure in your posting will not affect the whole flow of your API.

    So separate the insert transaction through the API from the posting process. Allowing potential errors to be handle in what my opinion is a better way.

  • DevPl320 Profile Picture
    5 on at

    Thanks for your time, job solution looks like the best option.

  • DomRot Profile Picture
    15 on at

    Hi, I search your post because I have same problem. After some search, I have seen that the event that fire after post request, is the OnBeforeCompanyClose.

    Subscribing this event in my cu, I can perform bc post documents.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    I would not recommend you to use that trigger for posting.

    You should look at some other event or some other way to do your posting.

    What is your buisness scenario ?

  • DomRot Profile Picture
    15 on at

    Hi Inge, thanks for your suggestion. I've tested this posting some inventory adjustment and worked fine.

    My api will receipt some other kind of docs like purchase receipts and sales invoice that I will try to posting in the next days.

    Why you do not recommend this trigger?

    Thanks again.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    If you want to perform a posting as part of an API call you should use the bound actions in the API.

    You can look here for some examples.

    docs.microsoft.com/.../devenv-creating-and-interacting-with-odatav4-bound-action

    robertostefanettinavblog.com/.../

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 518 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 362 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 327 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans