# How to create an api key on the admin panel

**URL:** https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383
**Category:** Development
**Tags:** rest-api
**Created:** [May 13, 2018, 11:15pm UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383 "2018-05-13T23:15:50Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![mattman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattman/32/119713_2.png) [@mattman](https://meta.discourse.org/u/mattman)
#### Post date: [May 13, 2018, 11:15pm UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/1 "2018-05-13T23:15:51Z")

</div>

I just got Discourse setup on Digital Ocean and I’m trying to tie it into my app on Bubble.

I found the API docs [https://docs.discourse.org/](https://docs.discourse.org/) which say that I need to create an API key on the admin panel.

 ![Screenshot%20from%202018-05-13%2016-13-05](https://global.discourse-cdn.com/meta/original/3X/c/6/c6cf7127be7cce5742a26c8d27f17e4b9b252b20.png)  
However, I don’t see any way to create a new API key.

I tried using that one API key in a parameter called “api\_key” on a test call and the message said it wasn’t accepted.

So I’d like to ask about how to get the user’s notification count but I can’t even get authenticated yet.

I’d be happy to educate myself but I can’t find any documentation or tutorials on how to get started calling the Discourse API.

---

<div class="post-metadata">

### Author: ![Noah751](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/noah751/32/82274_2.png) [@Noah751](https://meta.discourse.org/u/Noah751)
#### Post date: [May 14, 2018, 5:01am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/2 "2018-05-14T05:01:48Z")

</div>

You cannot create more than one api key, any reason why you can’t create more than one api key @codinghorror @sam.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 14, 2018, 5:44am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/3 "2018-05-14T05:44:58Z")

</div>

You can create one per user at the moment, not against changing it to allow multiple per user but there is a simple workaround (of creating api user per api key)

You can create as many user api keys as you want though per user.

---

<div class="post-metadata">

### Author: ![mattman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattman/32/119713_2.png) [@mattman](https://meta.discourse.org/u/mattman)
#### Post date: [May 14, 2018, 4:14pm UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/4 "2018-05-14T16:14:08Z")

</div>

Okay. So what do the API docs mean when they say “To become authenticated you will need to create an API Key from the admin panel”? That’s, like, the first step in the documentation.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 14, 2018, 5:41pm UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/5 "2018-05-14T17:41:13Z")

</div>

> [@mattman](#):
>
> Okay. So what do the API docs mean when they say “To become authenticated you will need to create an API Key from the admin panel”?

What it means is that when you start with a brand new install of Discourse you should not have an api key and when you go to the API tab it should look like this:

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/1/215abdeac50030ccaeb602ff9d4273fb7dc9e807.png)

So you will need to click that key icon to create a system wide api key. I’ll work on improving the docs about how to create a system key and how to make user api keys.

> [@mattman](#):
>
> I tried using that one API key

That key most definitely should work, most likely something else was the issue and you might need to provide more info with how you made the api request so that we can help you troubleshoot. Also please check if the content-type was set to form-data.

> [@mattman](#):
>
> So I’d like to ask about how to get the user’s notification count but I can’t even get authenticated yet.

You will need to hit the [`/notifications.json`](https://docs.discourse.org/#tag/Notifications%2Fpaths%2F~1notifications.json%2Fget) endpoint and pass in the user you want notifications for in the `api_username` field.

---

<div class="post-metadata">

### Author: ![mattman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattman/32/119713_2.png) [@mattman](https://meta.discourse.org/u/mattman)
#### Post date: [May 15, 2018, 2:11am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/6 "2018-05-15T02:11:46Z")

</div>

Oh, okay. Discourse was installed and setup for me so I didn’t see the step where the admin’s API key was generated.

I switched from application/json to form-data and got a different error, but it looks like I made it past the authentication step.

If I just included an api\_key then I got an error that either the key or username was wrong, which makes sense. If I include an api\_key and an api\_username then I get an error 422 “unprocessable entity” or an error 400 “invalid access” depending on what I put in the api\_username field.

What “username” am I supposed to use to identify an account? The user’s profile has two fields called “username” and the only one that’s populated is something that can be edited by the user.

I’m only allowing users to make a Discourse account by using SSO to pull in the account they already made on the Bubble app. There’s an “external ID” that seems to be the user’s unique ID from Bubble.

I tried replacing the api\_username field with external\_id but got the same “key or username is invalid” error.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [May 15, 2018, 2:29am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/7 "2018-05-15T02:29:16Z")

</div>

> [@mattman](#):
>
> If I just included an api\_key then I got an error that either the key or username was wrong, which makes sense. If I include an api\_key and an api\_username then I get an error 422 “unprocessable entity” or an error 400 “invalid access” depending on what I put in the api\_username field.

You want the 422 - that means there’s some other problem with the data you’re sending, other than the authentication.

---

<div class="post-metadata">

### Author: ![mattman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattman/32/119713_2.png) [@mattman](https://meta.discourse.org/u/mattman)
#### Post date: [May 15, 2018, 2:56am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/8 "2018-05-15T02:56:07Z")

</div>

I figured.  
But there’s only two fields.  
I’m confident the api\_key is correct, otherwise it would refuse access every time.  
So there’s something about the api\_username field that is passing authentication but is somehow invalid after that.

It’s not even clear what I’m supposed to put in the api\_username field, as I described in the previous post.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [May 15, 2018, 3:10am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/9 "2018-05-15T03:10:34Z")

</div>

> [@mattman](#):
>
> What “username” am I supposed to use to identify an account?

If you created an “all users” API key should the name be “system”?

[https://meta.discourse.org/t/get-user-data-remotely-api-database-curl/31415/4?u=mittineague](https://meta.discourse.org/t/get-user-data-remotely-api-database-curl/31415/4)

---

<div class="post-metadata">

### Author: ![mattman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattman/32/119713_2.png) [@mattman](https://meta.discourse.org/u/mattman)
#### Post date: [May 15, 2018, 3:20am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/10 "2018-05-15T03:20:58Z")

</div>

Putting “system” in the api\_username field does get me 422 “unprocessable entity” again.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [May 15, 2018, 3:28am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/11 "2018-05-15T03:28:40Z")

</div>

I could be off base, but “entity” reminds me of invalid URLs. eg. instead of `&amp;param=something` it interprets `&param` as an invalid entity. Maybe if you urlencode the ampersand?

---

<div class="post-metadata">

### Author: ![mattman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattman/32/119713_2.png) [@mattman](https://meta.discourse.org/u/mattman)
#### Post date: [May 16, 2018, 2:42am UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/12 "2018-05-16T02:42:02Z")

</div>

Hokay, so, I guess technically this topic is solved since the API key on the admin panel thing is resolved.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [March 15, 2024, 2:30pm UTC](https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383/13 "2024-03-15T14:30:37Z")

</div>


