Skip to content

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.

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

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.

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);

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 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.

If a response came with an error code, find it in Errors.

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