How to get an API key

I’m trying to programmatically create a topic with Python on a Discourse instance where I have the admin role.

The documentation states:

you will need to create an API Key from the admin panel

I have searched/looked in the admin panel, but I cannot find where I can generate this API key.

Unfortunately I have lost quite a bit of time already looking how to generate a key I can use as the Api-Key header. Should be simple? Where can I generate it?

In addition I don’t mind what kind of API key I can get, either system or my own username.

The only thing I care about is the ability to programmatically create a topic using a Python script.

Hello and welcome @dsclrsr :slightly_smiling_face:

You should be able to generate an api key from the admin api page [YourSite]/admin/api/keys

3 Likes

Ok turns out I am not a real admin, even though I can visit the admin panel over at /admin/ I cannot visit /admin/api/keys, I asked the hoster who setup the forum and he was able to create me a key at this location.

Seems to be a distinction between ‘admin’ (like a moderator) and ‘admin’ (like a system admin).

2 Likes

Ah yes. Moderator and Admin are distinct roles in Discourse. A Moderator has quite a lot of high level functions for user and content moderation, but an Admin (or Sysadmin) has access to far more settings and functions to do with setting up the forum itself. You can read more info about those roles in Description of various user states in Discourse (Admin / Moderator / Staff / Developer / Other)

2 Likes

Thanks for the help!

2 Likes

Hi @JammyDodger,

Could you explain the request parameters for that API or share the documentation?

I receive a response without the scopes parameter, but when I include the scopes parameter, it results in errors.

If possible, please share example code for that API. Thanks!