Using Endlinks with api calls

After your user has completed the flow you've implemented on your site, you need to report the outcome to TARTLE. The most flexible method for handling the result of your user's actions at the end of an endlink flow is to call one of the TARTLE Endlink endpoints from your backend or frontend code.

Depending on how you captured and saved the token, you will need to then retrieve it and add it to the appropriate endpoint.

For the examples below, we will use the complete endpoint, but you can use the other endpoints the same manner.

As before, for a more reliable implementation, we recommend doing this server-side.

Server-side examples

Server-side examples

const reportEndlinkComplete = async (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 false
  }

  try {
    const response = await fetch(
      `https://source.tartle.co/api/v3/endlinks/complete?tartle_endlink_token=${token}`,
    )

    if (!response.ok) {
      // WARNING: Log HTTP status code and response text you might need to work with TARTLE to resolve.
      return false
    }

    return true
  } catch (error) {
    // ERROR: Log error details you might need to work with TARTLE to resolve.
    return false
  }
}

Client-side examples

You can do this client side, but be aware that due to browser versions, security settings, and other factors, this is less reliable. Make sure you log errors thoroughly so you can debug any possible issues.

Client-side examples

function reportEndlinkComplete() {
  const token = localStorage.getItem('tartleEndlinkToken')

  if (!token) {
    // CRITICAL: Log missing token error - you will need it to debug possible issues.
    return false
  }

  try {
    const response = await fetch(
      `https://source.tartle.co/api/v3/endlinks/complete?tartle_endlink_token=${token}`
    )

    if (!response.ok) {
      // WARNING: Log HTTP status code and response text you might need to work with TARTLE to resolve.
      return false
    }

    return true
  } catch (error) {
    // ERROR: Log error details you might need to work with TARTLE to resolve.
    return false
  }
}

Considerations

  • The tartle_endlink_token is only valid for one hour, so make sure you call the endpoint within that time frame.
  • 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.

Was this page helpful?