2222
2323** Creates** a new API key and returns the actual key.
2424
25+ An API Key may have various scopes attached to it. If no scopes get passed
26+ a default set of scopes will be assigned. ** Please note** : By default the
27+ scopes are very permissive to support a wide range of use cases.
28+
29+ As an example, a restrictive scope might look like this:
30+ ``` json
31+ scopes: [{
32+ resource: 'listeners',
33+ access: 'write',
34+ targets: [
35+ 'MbCS6UB_m7NdvyDOE8stT',
36+ 'YKOuoR5IIUUWxZeZLKf2O'
37+ ]
38+ }, {
39+ resource: 'queues',
40+ access: 'write',
41+ targets: '*'
42+ }, {
43+ resource: 'messages',
44+ access: 'read',
45+ targets: '*'
46+ }]
47+ ```
48+
2549<Badge type =" warning " text =" Note " vertical =" middle " /> For security reasons, the
2650API key will only be returned once after its creation.
2751
@@ -39,22 +63,79 @@ See also: [Authentication](/getting-started/#prerequisites).
3963
4064``` shell
4165curl -X POST http://api.discue.io/v1/api_keys \
66+ -H ' Content-Type: application/json' \
4267 -H ' Accept: application/json' \
43- -H ' X-API-KEY: API_KEY'
68+ -H ' X-API-KEY: API_KEY' \
69+ -d ' {
70+ "name": "string",
71+ "status": "disabled",
72+ "scopes": [
73+ {
74+ "resource": "queues",
75+ "access": "write",
76+ "targets": [
77+ "*"
78+ ]
79+ },
80+ {
81+ "resource": "listeners",
82+ "access": "write",
83+ "targets": [
84+ "_Tzrg1O3jk4_FZTAEThNq"
85+ ]
86+ },
87+ {
88+ "resource": "messages",
89+ "access": "read",
90+ "targets": [
91+ "*"
92+ ]
93+ }
94+ ]
95+ }'
4496```
4597
4698</CodeGroupItem >
4799
48100<CodeGroupItem title =" javascript " >
49101
50102``` javascript
103+ const body = {
104+ " name" : " string" ,
105+ " status" : " disabled" ,
106+ " scopes" : [
107+ {
108+ " resource" : " queues" ,
109+ " access" : " write" ,
110+ " targets" : [
111+ " *"
112+ ]
113+ },
114+ {
115+ " resource" : " listeners" ,
116+ " access" : " write" ,
117+ " targets" : [
118+ " _Tzrg1O3jk4_FZTAEThNq"
119+ ]
120+ },
121+ {
122+ " resource" : " messages" ,
123+ " access" : " read" ,
124+ " targets" : [
125+ " *"
126+ ]
127+ }
128+ ]
129+ }
130+
51131const headers = {
132+ ' Content-Type' : ' application/json' ,
52133 ' Accept' : ' application/json' ,
53134 ' X-API-KEY' : ' API_KEY'
54135}
55136
56137const response = await fetch (' http://api.discue.io/v1/api_keys' , {
57- method: ' POST' , headers
138+ method: ' POST' , body, headers
58139})
59140
60141const body = await response .json ()
@@ -67,6 +148,7 @@ const body = await response.json()
67148``` python
68149import requests
69150headers = {
151+ ' Content-Type' : ' application/json' ,
70152 ' Accept' : ' application/json' ,
71153 ' X-API-KEY' : ' API_KEY'
72154}
@@ -89,6 +171,7 @@ import (
89171func main () {
90172
91173 headers := map [string ][]string {
174+ " Content-Type" : []string {" application/json" },
92175 " Accept" : []string {" application/json" },
93176 " X-API-KEY" : []string {" API_KEY" },
94177 }
@@ -106,10 +189,70 @@ func main() {
106189
107190</CodeGroup >
108191
192+ ## Body
193+
194+ ``` json
195+ {
196+ "name" : " string" ,
197+ "status" : " disabled" ,
198+ "scopes" : [
199+ {
200+ "resource" : " queues" ,
201+ "access" : " write" ,
202+ "targets" : [
203+ " *"
204+ ]
205+ },
206+ {
207+ "resource" : " listeners" ,
208+ "access" : " write" ,
209+ "targets" : [
210+ " _Tzrg1O3jk4_FZTAEThNq"
211+ ]
212+ },
213+ {
214+ "resource" : " messages" ,
215+ "access" : " read" ,
216+ "targets" : [
217+ " *"
218+ ]
219+ }
220+ ]
221+ }
222+ ```
223+
109224## Parameters
110225| Name| In| Type| Required| Description|
111226| ---| ---| ---| ---| ---|
112227| pretty| query| boolean| ❌ | Return the response pretty printed|
228+ | body| body| [ PostApiKeyRequest] ( #schemapostapikeyrequest ) | ❌ | none|
229+ | » name| body| [ ResourceName] ( #resourcename ) | ❌ | none|
230+ | » status| body| string| ❌ | none|
231+ | » scopes| body| [ ApiKeyScope] ( #apikeyscope ) | ❌ | none|
232+ | »» resource| body| string| ❌ | none|
233+ | »» access| body| string| ❌ | none|
234+ | »» targets| body| any| ❌ | none|
235+ | »»» * anonymous* | body| [ ResourceId] ( #resourceid ) | ❌ | none|
236+ | »»» * anonymous* | body| string| ❌ | none|
237+
238+ ## Enumerated Values
239+
240+ | Parameter| Value|
241+ | ---| ---|
242+ | » status| disabled|
243+ | » status| enabled|
244+ | »» resource| api_clients|
245+ | »» resource| api_keys|
246+ | »» resource| events|
247+ | »» resource| queues|
248+ | »» resource| listeners|
249+ | »» resource| messages|
250+ | »» resource| schemas|
251+ | »» resource| stats|
252+ | »» resource| subscriptions|
253+ | »» access| read|
254+ | »» access| write|
255+ | »»» * anonymous* | * |
113256
114257## Responses
115258
0 commit comments