How to get an API key

AI-generated summary

A user, dsclrsr, seeks guidance on obtaining an API key for programmatically creating topics on a Discourse instance using Python. Despite having admin panel access, they cannot generate the key, as the /admin/api/keys page is restricted. JammyDodger clarifies that access to this page requires a full Admin (system admin) role, not just a moderator role, and provides a link to Discourse’s role documentation 35171. The user confirms the issue was resolved by the hoster, who granted the necessary permissions. Another user, Robert_Mercado, then asks for clarification on the API request parameters, particularly the scopes field, and requests example code.

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

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

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 Understanding user statuses, roles, and permissions

Thanks for the help!

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!