# Website

Show a goal, top donors or a total on your own page: the request goes straight from the browser. You need a website at an `http://` or `https://` address; a page opened from a file will not work.

## 1. Issue a public key

In the «Публичный ключ» (Public key) block, press «Выпустить публичный ключ» (Issue public key). Enter the website address: protocol, domain and port if there is one, no path, for example `https://mysite.example`. Press «Выпустить ключ» (Issue key) and copy the key.

Every visitor can see the key, so it opens only the profile, goals and stats.

[Open Developers in your dashboard](https://streamer.donatty.com/developers)

## 2. Request data

Paste the code into your page inside `<script type="module">` and replace `dnt_pk_...` with your public key. The code requests the active goal and prints it to the browser console.

```js
const response = await fetch("https://api.donatty.com/v1/goals?status=ACTIVE&limit=1", {
    headers: {Authorization: "Bearer dnt_pk_..."},
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const {items} = await response.json();
console.log(items);
```

## Add the addresses your page opens from

The key works only on addresses from its list. To test the page on your computer, add a second address, such as `http://localhost:8080`: click «Настроить ключ» (Configure key) next to the public key, add the address and click «Сохранить адреса» (Save addresses). A key can have up to 20 addresses.

## If the request fails

If the browser console shows `blocked by CORS policy` and `fetch` fails with `TypeError: Failed to fetch`, first check the page address: it must be in the key's list. Compare it with the address bar: the protocol, domain and port must match. More: [origin_not_allowed](https://developers.donatty.com/en/errors/origin_not_allowed.md).

If a response came with an error code, find it in [Errors](https://developers.donatty.com/en/errors.md).

The public key works from the reference only if its addresses include `https://developers.donatty.com`.

## Next

- [Ready-made goal page](https://developers.donatty.com/en/examples/goal-html.md)
- In OBS, you can show the page as a «Браузер» (Browser) source with the same address.
- [Method parameters](https://developers.donatty.com/en/reference.md)
