Keys and authentication

Create an API key, choose read-only or read & write, send it with every request, and revoke it when you're done.

Every request carries one of your API keys. A key acts as you, for your prop accounts only, so treat it like a password.

Creating a key

  1. Sign in and open API keys (in the menu, under Settings).
  2. Give the key a name you'll recognise later, like "Journal sync script".
  3. Choose its access:
    • Read-only: can read your accounts, figures, days and payouts.
    • Read & write: can also add and change accounts, log and delete days and payouts, archive and restore accounts, and switch sharing.
  4. Choose when it expires: after 30 days, 90 days, a year, or never.
  5. Copy the key. It is shown once. We keep only a fingerprint of it, so nobody (us included) can show it to you again.

If your account uses two-factor authentication, you'll need to have signed in with it to create or revoke keys.

You can have up to 20 active keys (and 1,000 in all, revoked ones included). Give each script its own key, so you can revoke one without breaking the others.

Using a key

Send the key in the Authorization header as a bearer token:

curl https://degenandfriends.com/api/v1/me \
  -H "Authorization: Bearer dfk_your_key_here"
{
  "key": { "id": "b2d1…", "scope": "write" },
  "member": { "id": "51953dd1…", "handle": "your_handle" }
}

GET /me is a handy check that a key works.

Keys look like dfk_ followed by 43 letters, digits, - and _. The page lists each key by its first few characters, when it was last used, and when it expires.

A read-only key that tries to change something gets 403 read_only_key.

Keeping keys safe

  • Keep keys out of code you share and out of version control: read them from an environment variable.
  • Use read-only keys wherever you only need to look.
  • Give keys an expiry unless they really must run forever.
  • If a key may have leaked, revoke it on the API keys page. It stops working at once, and can't be brought back; create a new one.

A key also stops working when it expires, or if your Degen & Friends account is suspended.

In code

JavaScript (Node 18+ or the browser of your own tool):

const response = await fetch('https://degenandfriends.com/api/v1/accounts', {
  headers: { Authorization: `Bearer ${process.env.DF_API_KEY}` },
});

const { accounts } = await response.json();

Python:

import os, requests

response = requests.get(
    "https://degenandfriends.com/api/v1/accounts",
    headers={"Authorization": f"Bearer {os.environ['DF_API_KEY']}"},
)
accounts = response.json()["accounts"]