Using Endlinks with browser redirects
After your user has completed the flow you've implemented on your site, you need to report the outcome to TARTLE. One approach is to use browser redirects to send users directly to the appropriate TARTLE endpoint. This method is very simple to implement, but will take users away from your site.
Depending on how you captured and saved the token, you will need to retrieve it and include it in the redirect URL to the appropriate endpoint.
For the examples below, we will use the complete
endpoint, but you can use the other endpoints in the same manner.
Server-side examples
These examples show how to implement redirects from your server:
Server-side redirect examples
const redirectToTartleComplete = (req, res) => {
const token = req.session.tartle_endlink_token
if (!token) {
// CRITICAL: Log missing token error - you will need it to debug possible issues.
return res.status(400).send('Cannot complete TARTLE flow: Missing token')
}
// Redirect the user to the TARTLE complete endpoint
return res.redirect(
`https://source.tartle.co/api/v3/endlinks/complete.html?tartle_endlink_token=${token}`,
)
}
Client-side examples
You can also implement redirects client-side. You could add the complete url as the href
attribute to an anchor tag or
use the window.location.href
property to redirect the user.
Client-side redirect examples
<a
href="https://source.tartle.co/api/v3/endlinks/complete.html?tartle_endlink_token=YOUR_TOKEN"
>Get your reward</a
>
Considerations
- The
tartle_endlink_token
is only valid for one hour, so make sure you perform the redirect within that time frame. - Browser redirects will take users away from your site. If you want to provide a seamless experience, consider using the API-based approach instead.
- Please make sure to log errors and failures so you can debug any issues, if you don't report an outcome due to an error, we will treat it as a failure, and the user will not receive payments for this packet.
Having issues? See our Endlink troubleshooting guide.