JavaScript SDK
Add Javascript SDK to your Front-end
If you are using one of the popular JS frameworks, check out a framework-specific article:
First, install @membranehq/sdk NPM package:
npm install @membranehq/sdkAlternatively, you can install @membranehq/sdk over any public CDN:
<html lang="en">
<head>
<!-- Use latest version -->
<script src="https://cdn.jsdelivr.net/npm/@membranehq/sdk/dist/bundle.js"></script>
<!-- Use specific version -->
<script src="https://cdn.jsdelivr.net/npm/@membranehq/[email protected]/dist/bundle.js"></script>
<script>
console.log(MembraneClient)
</script>
</head>
<body></body>
</html>Then, initialize the SDK with an Authentication Token:
import { MembraneClient } from "@membranehq"
const membrane = new MembraneClient({
// Test authentication token. You will need to replace it with the real one.
token: "",
})In this example we use the test token you can find on the Settings page of your workspace.
You will need to replace it with a real authentication token later (see Authentication).
To verify that everything works, let's open our drop-in integration UI:
await membrane.open()Dynamic Token
If it is more convenient for you to fetch token dynamically instead of providing static value, you can use fetchToken instead:
import { MembraneClient } from "@membranehq"
const membrane = new MembraneClient({
// Test authentication token. You will need to replace it with the real one.
async fetchToken() {
return ""
},
})This option also automatically handles token expiration. If SDK was initialized long ago and token had time to expire, it will be automatically re-fetched before making new API requests.
SDK Reference
To see the full list of SDK methods check out the JavaScript API Reference
Updated 11 days ago
