Skip to content
Avandby Shokoofa AI
All documentation

Third-party sites

Let your own website show the Avand explorer, so its visitors choose or manage their own files.

Any https website can show the Avand explorer: a button that lets visitors choose one of their files, or a panel where they manage them. Visitors use their own Avand account; your site never sees a password or a token, only short-lived links to the files they choose.

1. Register your site

In Account, open Embed apps and add one. Pick what you want (an image picker, a file picker or a file manager), name it as your visitors should see it, and paste your site's address. Any address of the site works: only its origin is kept (https://shop.example.com/admin becomes https://shop.example.com). Add every address the page will run on, up to ten.

2. Paste the code

Once the app is added, Avand shows its code. Choose how it should appear, copy it and paste it into your page. The button style needs no JavaScript of your own:

<script src="https://avand.shokoofa.ai/explorer.js" defer></script>
<input id="avand-file" name="file" type="url" />
<button
  type="button"
  data-avand-open
  data-app="<your app id>"
  data-mode="pick"
  data-accept="image/*"
  data-target="#avand-file"
>
  Choose from Avand
</button>

The chosen file's link is written into the field and submitted with your form. For a panel inside the page, use <div data-avand-explorer data-app="<your app id>" data-height="480"></div>. Both fire avand:ready, avand:select (the chosen files in event.detail) and avand:close. The other attributes: data-mode (pick or browse), data-accept, data-multiple (a textarea receives one link per line), data-path, data-lang (fa or en). For full control, AvandExplorer.open({ embedApp, onSelect, ... }) is described at the top of explorer.js.

A system account's app (no sign-in)

An app an Avand administrator registers for a system account shows that account's zones, and nobody signs in: your server asks Avand for a ticket with the account's key, and the page hands it to the explorer. The administration page shows the code for both sides.

  1. Keep the account's system key (avand_ak_...) on your server only, in the AVAND_API_KEY environment variable: never in the page, a cookie or a URL.
  2. Add an endpoint to your site, behind your own sign-in, that asks Avand for a ticket and answers the page { "ticket": "..." }:
// Node 18+ with Express
app.post("/avand-ticket", async (req, res) => {
  // Check your own sign-in first: whoever gets a ticket gets the explorer.
  const response = await fetch("https://avandapi.shokoofa.ai/api/v1/embed/tickets", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.AVAND_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ embedAppId: "<your app id>", origin: "https://shop.example.com" }),
  });
  const answer = await response.json();
  if (!response.ok) return res.status(502).json({ error: answer.code });
  res.set("Cache-Control", "no-store").json({ ticket: answer.ticket });
});
  1. Name that endpoint in the page with data-ticket-url, or pass getTicket (a function returning a promise of the ticket) to AvandExplorer.open or mount:
<script src="https://avand.shokoofa.ai/explorer.js" defer></script>
<div data-avand-explorer data-app="<your app id>" data-ticket-url="/avand-ticket"></div>

The explorer asks for a ticket each time it opens and again when its session ends. A ticket works once, for 60 seconds, only for this app on this site, and it is handed over by message, never in a URL. The key the ticket becomes stays on Avand's server and expires within hours; revoking your key or the app closes every open explorer at once. The same code is offered in PHP, Python and curl.

How it works

  • The first time, a visitor signs in to Avand in a popup window and approves your site. Later visits ask nothing until they withdraw it in Connected sites.
  • The page's address must match a registered address exactly, or the explorer won't load.
  • Only https sites can embed Avand.
  • Links to chosen files are short-lived. Save the file itself if you need it later.
  • Changing the addresses or what the site may do asks every visitor to approve again.