Skip to main content
When the user finishes their chat or conversion flow, close the AdMesh session.
  • TypeScript/JavaScript
  • React
  • Android (Kotlin)
  • Flutter (Dart)
  • Swift/iOS
  • React Native
export async function closeAdmeshSession() {
  const sessionId = localStorage.getItem("admesh_session_id");
  if (!sessionId) return;

  try {
    const response = await fetch("https://api.useadmesh.com/agent/session/close", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ session_id: sessionId }),
    });

    if (response.ok) {
      const data = await response.json();
      console.log("✅ Session closed:", data);
      localStorage.removeItem("admesh_session_id");
    } else {
      console.error("❌ Failed to close session:", response.status);
    }
  } catch (error) {
    console.error("❌ Error closing session:", error);
    localStorage.removeItem("admesh_session_id");
  }
}

Response

When the session is successfully closed, you’ll receive a 200 OK response. That’s it , the session is closed. No need to parse stats or additional data.

When to close

  • User closes chat or tab
  • Conversion completes
  • Platform resets context
  • User logs out

Integration complete! You now have a fully functional AdMesh integration.