Reload after api call succeed

Hi, I have an api call button that trigger a scenario in make.com
after the api call succeed, I want to reload the page so that user can see the result. How can I achieve this? I have these code but it does not work

window.addEventListener('block-loaded-list1', () => {
	window.addEventListener('call-api-success-list1', (e) => {
		setTimeout(() => {
			window.dispatchEvent(new CustomEvent('reload-list1'));
		}, 3000);
	});
});

thanks in advance

Hi there! This can be done using custom code, though I don’t have the exact snippet. Maybe @acjnas or @matthieu_chateau can help when they have a moment.

This should work (if you have <script> </script> and the code placed in the header custom code of the page settings)

<script>
window.addEventListener('block-loaded-list1', () => {
    window.addEventListener('call-api-success-list1', (e) => {
        setTimeout(() => {
            window.dispatchEvent(new CustomEvent('reload-list1'));
        }, 3000);
    });
});
</script>

Be sure list1 is a beta list block, otherwise it should reload-block-list1, not reload-list1

@matthieu_chateau thankyou for your answer, but it still does not work. I have beta list block, I’m using the Grid style. Below is my code
image

@artur a lot of people have problems with the event listeners window.addEventListener(‘call-api-success-blockID’ => I don’t know why.

@tirza in your make scenario, do you have a webhook response module? (No need for it by the way, just want to give some context)

@matthieu_chateau I can add it though, but in custom code we still need the trigger like “update-record-success” or “call-api-success” right? So I think it will produce the same problem

I will wait for Artur’s answer because this api-call event listener is not working for a lot of people/ People having issues with it.

If you would add a webhook response, you wouldn’t need trigger like “update-record-success” or “call-api-success. You would need another script in your page I can provide if this is urgent.

@matthieu_chateau yes please

@matthieu_chateau I have found the working code, below is the code
Sveta from softr helped me achieve this

window.addEventListener(‘block-loaded-list1’, () => {
setTimeout(() => {
window.dispatchEvent(new CustomEvent(‘reload-list1’));
}, 3000);
});

**edited

it only worked once :sweat_smile:

Great!
@artur (or @Jjenglert if you could ask) how is it possible this code works? :sweat_smile:

1 Like

@matthieu_chateau right it should end up in a loop. I though have an idea that loaded is when entire list is loaded first time and reload mostly does data fetching… I will confirm and get back

@tirza can you please DM me the app URL and add support@softr.io as a collaborator ?

We will then check and find out what’s the issue.

Additionally are you saying the call-api-success doesn’t work for you at all or it works only once ?

Hello @tirza, I suppose for beta List block this code should work. The issue here is that call-api-success-blockid is not implemented except for trigger webhook action. So removing it from the custom code should fix the issue. Could you please check it out?

<script>
    window.addEventListener('block-loaded-blockid', () => {
        setTimeout(() => {
            window.dispatchEvent(new CustomEvent('reload-block-blockid'));
        }, 5000);
    });
</script>

@artur I already sent you a DM
On Friday when I tried it for the first time, it works
but after I tried it on the second time, it did not work

hi, thank you for your reply
I have my code edited by softr support. Now my code looks like this but it still does not work at all

Thanks for your response @tirza . We deployed a minor fix, could you please check if this code works as you expected

<script>

    window.addEventListener('call-api-success-list1', (e) => {
        setTimeout(() => {
            window.dispatchEvent(new CustomEvent('reload-block-list3'));
            alert("reload triggered");
        }, 1000);
    });

</script>

this code does not work too, can I just reload the page whenever any button clicked? @Viktoria

@tirza would you mind sharing the magic link and page URL so we could check on your app and provide the appropriate custom code?

I will send you a message, thank you

Not sure if this is still relevant but the original question was to reload the page after a succesfull api call?

    window.addEventListener('call-api-success-list-details2', () => {
        setTimeout(() => {
               window.location.reload()
        }, 2000);
	});

This one worked for me and is a lot less complex :stuck_out_tongue: not a webdev guru though

1 Like