Navigate to page after Call API button pressed

I have a Call API button in an item details block. When the user presses it I want the API to be called (which works) but also for the page to navigate to /main. There are two buttons in this block and I only want this functionality for the button “Finalize Config”. Here’s the custom code I tried. I am a no-coder so someone provided this in this forum but it’s not working.

<script>
  window.addEventListener('block-loaded-item-details1', () => {
    window.addEventListener('update-record-success-item-details1', () => {
      window.location.href = '/main';
    });
  });
</script>

Hi Dylan,

When you use an api call action button, the event listener is not update-record-success but call-api-success.

So your script should look like this instead:

<script>
  window.addEventListener('block-loaded-item-details1', () => {
    window.addEventListener('call-api-success-item-details1', () => {
      window.location.href = '/main';
    });
  });
</script>
1 Like

Thanks for your help, @matthieu_chateau

1 Like