API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#API Connect
#Applicationintegration
#APIConnect
 View Only
Expand all | Collapse all

implementing hooks

  • 1.  implementing hooks

    Posted Wed March 06, 2024 03:00 PM

    Hi 

    I am doing some POC and trying to implement below hooks 

    hook_apic_app_subscribe

    hook_apic_app_create

    basically i want do something when app or subscription is created but I also want to make sure if there was any failure , original app should not be created or subscription should also fail.

    Can you please suggest me how to implement that or this can be part of error handling of hook implementation.

    Thank you,

    Imtiyaz



    ------------------------------
    Syed Imtiyaz Alam
    ------------------------------


  • 2.  RE: implementing hooks

    Posted Thu March 07, 2024 05:10 AM

    We have a sample module which demonstrates the use of the hooks you are interested in available on our sample module github repo  .Can you clarify what you are trying to do?  Are you attempting to create and app and subscribe to a product plan at the same time?



    ------------------------------
    Anne Redwood
    ------------------------------



  • 3.  RE: implementing hooks

    Posted Thu March 07, 2024 11:04 PM
    1. During App onboarding/creation: We will alter the form and add some more text field which we want to insert those data to our internal DB by implementing hook_apic_app_create and we want to make sure if for what ever reason inserting to DB fails , it should fail the creation of the credentials. This is applicable for all different operation i.e. any updates/delete, we want to update our internal DB and if that fails, then actual updates or deletes fails.
    2. Similar use case for subscription , when ever subscription is requested , we want to check our internal DB for some configuration and if that fails or based on some response then we want to fail the subscription also or proceed with the subscription.

    I hope this helps.



    ------------------------------
    Syed Imtiyaz Alam
    ------------------------------



  • 4.  RE: implementing hooks

    Posted Fri March 08, 2024 05:24 AM

    The hooks hook_apic_app_create and hook_apic_app_subscribe are always called after the create or subscribe.  You are wanting to alter the form so you will need to use the hook_form_alter to add pre submit validation to the form you are altering.

    Hope this helps,

    Anne



    ------------------------------
    Anne Redwood
    ------------------------------



  • 5.  RE: implementing hooks

    Posted Mon March 11, 2024 03:34 PM

    Hi Anne,

    for App creation, yes we will alter the form to add few more custom field for consumer to enter but we would also need the credentials info like app name/app sub name or app id generated so we cant use before submit.

    And for subscription , we will be using as it is i.e. after subscription request is made , internally we would also check our internal DB. There is no alteration on the page.

    the above is my thought and as for both case hooks were available so wanted to understand how do make sure both are tied together.

    thank you the feedback.



    ------------------------------
    Syed Imtiyaz Alam
    ------------------------------



  • 6.  RE: implementing hooks

    Posted Tue March 12, 2024 06:00 AM

    So you are wanting some kind of rollback based on whether your internal Database has failed or not?  

    hook_form_alter is to use before app creation/ app subscription

    hook_apic_app_subscribe is to use after app subsrciption

    hook_apic_app_create is to use after app create

    What you seem to be implying is that you want to customise the app creation and subscription as it happens, which is internal portal code and alteration of that is not supported.



    ------------------------------
    Anne Redwood
    ------------------------------



  • 7.  RE: implementing hooks

    Posted Wed March 13, 2024 10:04 AM

    So you are wanting some kind of rollback based on whether your internal Database has failed or not?   >> YES rollback.

    When you say "alteration of that is not supported." , do you mean this is not feasible via Drupal or IBM does not support.

    Any suggestions how we can achieve this use case.



    ------------------------------
    Syed Imtiyaz Alam
    ------------------------------



  • 8.  RE: implementing hooks

    Posted Wed March 13, 2024 10:43 AM

    Alteration of our source code is not supported i.e you cannot modify the code at the point of app creation or subscription. 

    Remember the portal doesn't directly create an application or subscribe an application to a product plan - this is done as consumer api call to the api manager.  To have cannot have application credentials without an app being created.

    To perform the kind of rollback you need to do you would need to perform the opposite action of what you have done i.e. delete or unsubscribe.  This you would need to do in your own custom code using the hooks you have previously identified, attempt what you need to do on your internal DB/system and if it fails use the consumer api to perform that a delete or unsubscription of the app.



    ------------------------------
    Anne Redwood
    ------------------------------



  • 9.  RE: implementing hooks

    Posted Wed March 20, 2024 05:11 PM

    another thought

    During APP creation , we are adding some fields thus we can add some validation on those field to connect to internal DB and check few things and during this time submit button is not enabled for user. But yes this does not solve all the use case like connection failure. and during that time we roll back. 

    Can you please confirm at-least hooks are called only after actual application or subscription was successfully. ?



    ------------------------------
    Syed Imtiyaz Alam
    ------------------------------



  • 10.  RE: implementing hooks

    Posted Thu March 21, 2024 02:10 AM

    All portal hooks will be after the artifact (app or sub) has already been created in apim. The only exception would be hook_form_alter which you could use to do something before the call is even made to api manager. But obviously you won't have anything like the app id or client id at that point because it hasn't been created yet.

    Fundamentally the important point to remember is api manager owns these items and is the system or truth. That limits what you can do in the portal.



    ------------------------------
    Chris Dudley
    ------------------------------