Backend call on thank you page

Hello,

So i need to redirect my user from the thank you page (using an extension target of purchase.thank-you.block.render) to a custom backend call when they click on a button, how can i achieve this?

Hi @tomasrsd

Ah, I do have an idea on this.

But first, you cannot use standard JavaScript commands like window.location to redirect users because Shopify Checkout Extensions run in a secure sandbox that blocks access to the window object.

The most simple solution is to use the Link component from the Shopify UI Extensions library. Since standard Buttons cannot trigger navigation, you must render a Link element that points to your backend URL. You can style this link to look more prominent, but it must remain a link element.

Hope this helps!

Hello @tomasrsd ,

You cannot directly redirect the user automatically from the Thank You page or freely navigate them to arbitrary URLs. However, you can redirect them when they click a button, with some constraints.

Using purchase.thank-you.block.render

You cannot

  • Auto-redirect users on page load
  • Run arbitrary JS redirects
  • Call your backend directly from the browser without CORS/security handling

You can

  • Add a button
  • Handle a button click
  • Navigate the user to a URL (including one that triggers backend logic)

Flow

  1. User clicks a button on the Thank You page
  2. Your extension:
  • Calls your backend OR
  • Redirects to a backend-controlled URL
  1. Backend processes the order (via order ID / checkout token)
  2. Backend optionally redirects the user again

Aa dam it, okay that might work as temporary solution, thank you!

After the removal of script tags the only way to redirect a user is by the user initiating it via clicking on a button. Here is an example that I have set up using the Checkout Plus app to achieve the redirect via a button click.