web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • JV-15051434-0 Profile Picture
    27 on at
    Perform action after API request
    Hi Guys,
     
    I think that the post action is a really weird one. Sure it is cool that you can call it, but when working with other interfaces this is really not practical. There should be an action like OnAfterApiPayload or something like that. Which in my opinion could be done in the C# source code of AL.
     
    How i solved it in a real live situation is to add a field for the last line. So if you post an sales order, the last sales line has the field "LastLine" boolean true. You can then start a session from the onafterinsertSalesLine (or something like that). The sending side has to put that in the json message. The benefit is that it is in one call, so there is no risk of first sending the data and then failing the action post. 
     
    Another idea is to start a session that checks if the order is in after a certain amount of time. Lame, i know, but better then some sort of job queue that can also fail after an update or something.
     
    Bottomline, if there is an idea to make a OnAfterApiPayload event i would vote for it. Heck i'll even campagne for it to make it real. That would save a lot of headaches. 
  • TriposDev Profile Picture
    10 on at
    RE: Perform action after API request

    Hi, I have a different scenario:

    When I call my API, I have to skip all onValidate triggers in the table because I always get all the errors related to empty fields even if they are all filled.

    So I created an event in the table that uses the standard "isHandled" method, but I'm using the User Setup table to set a custom boolean field (isApi).

    So, when the OnOpenPage trigger (in the page API) is executed, I set the isApi field in User Setup to true.

    So far, it works. My problem is setting it back to false when the call is ended.

    I tried OnClosePage and OnQueryClosePage too, but the field is always true now; even if the page is closed.

  • YUN ZHU Profile Picture
    90,354 Super User 2025 Season 2 on at
    RE: Perform action after API request

    Hi, just adding a simple example.

    How to run AL procedure in Power Automate (Add custom execute actions)

    https://yzhums.com/20111/

    Hope this helps as well.

    Thanks.

    ZHU

  • DomRot Profile Picture
    15 on at
    RE: Perform action after API request

    Thanks you very much Inge.

  • Inge M. Bruvik Profile Picture
    1,035 Moderator on at
    RE: Perform action after API request

    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/.../

  • DomRot Profile Picture
    15 on at
    RE: Perform action after API request

    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.

  • Inge M. Bruvik Profile Picture
    1,035 Moderator on at
    RE: Perform action after API request

    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
    RE: Perform action after API request

    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.

  • DevPl320 Profile Picture
    5 on at
    RE: Perform action after API request

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

  • Inge M. Bruvik Profile Picture
    1,035 Moderator on at
    RE: Perform action after API request

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,710

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 2,675 Super User 2025 Season 2

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,203

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans