Browser SDK
Load the hosted SDK
<script type="module">
import "https://hashbin.org/sdk/hashbin.js";
hashbin.configure({
clientId: "app_123",
redirectUri: "https://your-app.example/hashbin/callback",
contentBaseUrl: "https://256t.us"
});
</script>
Start authorization
await hashbin.authorize({
scopes: ["content:write", "balance:read"],
mode: "redirect"
});
For popup flows, call mode: "popup" and let your callback page call hashbin.handleCallback({ postMessageToOpener: true, closeWindow: true }).
Complete the callback
import "https://hashbin.org/sdk/hashbin.js";
hashbin.configure({
clientId: "app_123",
redirectUri: "https://your-app.example/hashbin/callback",
contentBaseUrl: "https://256t.us"
});
await hashbin.handleCallback();
Publish, retrieve, and read balance
const balance = await hashbin.getBalance();
console.log(balance.balance_cents);
const result = await hashbin.publish("hello world", {
contentType: "text/plain"
});
console.log(result.cid, result.url);
const contentUrl = hashbin.getContentUrl(result.cid, { download: true });
const response = await hashbin.retrieve(result.cid);