Create an api key

POST /api_keys

Creates a new API key and returns the actual key.

An API Key may have various scopes attached to it. If no scopes get passed a default set of scopes will be assigned. Please note: By default the scopes are very permissive to support a wide range of use cases.

As an example, a restrictive scope might look like this:

  scopes: [{
    resource: 'listeners',
    access: 'write',
    targets: [
      'MbCS6UB_m7NdvyDOE8stT',
      'YKOuoR5IIUUWxZeZLKf2O'
    ]
  }, {
    resource: 'queues',
    access: 'write',
    targets: '*'
  }, {
    resource: 'messages',
    access: 'read',
    targets: '*'
  }]

Protected scopes like api_clients, api_keys and subscriptions cannot be set via API.

Note For security reasons, the

API key will only be returned once after its creation.

Authentication

The target organization for this request will be determined by the supplied access token.

As a prerequisite you need to create an accountopen in new window and follow the onboarding process to also create an organization and an API key.

See also: Authentication.

Examples

curl -X POST http://api.discue.io/v1/api_keys \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'X-API-KEY: API_KEY' \
  -d '{
  "name": "string",
  "status": "disabled",
  "scopes": [
    {
      "resource": "queues",
      "access": "write",
      "targets": [
        "*"
      ]
    },
    {
      "resource": "listeners",
      "access": "write",
      "targets": [
        "_Tzrg1O3jk4_FZTAEThNq"
      ]
    },
    {
      "resource": "messages",
      "access": "read",
      "targets": [
        "*"
      ]
    }
  ]
}' 
const body = {
  "name": "string",
  "status": "disabled",
  "scopes": [
    {
      "resource": "queues",
      "access": "write",
      "targets": [
        "*"
      ]
    },
    {
      "resource": "listeners",
      "access": "write",
      "targets": [
        "_Tzrg1O3jk4_FZTAEThNq"
      ]
    },
    {
      "resource": "messages",
      "access": "read",
      "targets": [
        "*"
      ]
    }
  ]
}

const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'X-API-KEY':'API_KEY'
}

const response = await fetch('http://api.discue.io/v1/api_keys', {
  method: 'POST',  body,  headers
})

const body = await response.json()
import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'X-API-KEY': 'API_KEY'
}

r = requests.post('http://api.discue.io/v1/api_keys', headers = headers)
package main

import (
  "bytes"
  "net/http"
)

func main() {

  headers := map[string][]string{
      "Content-Type": []string{"application/json"},
      "Accept": []string{"application/json"},
      "X-API-KEY": []string{"API_KEY"},
  }

  data := bytes.NewBuffer([]byte{jsonReq})
  req, err := http.NewRequest("POST", "http://api.discue.io/v1/api_keys", data)
  req.Header = headers

  client := &http.Client{}
  resp, err := client.Do(req)
}

Body

{
  "name": "string",
  "status": "disabled",
  "scopes": [
    {
      "resource": "queues",
      "access": "write",
      "targets": [
        "*"
      ]
    },
    {
      "resource": "listeners",
      "access": "write",
      "targets": [
        "_Tzrg1O3jk4_FZTAEThNq"
      ]
    },
    {
      "resource": "messages",
      "access": "read",
      "targets": [
        "*"
      ]
    }
  ]
}

Parameters

NameInTypeRequiredDescription
prettyquerybooleanReturn the response pretty printed
bodybodyPostApiKeyRequestnone
» namebodyResourceNamenone
» statusbodystringnone
» scopesbodyApiKeyScopenone
»» resourcebodystringnone
»» accessbodystringnone
»» targetsbodyanynone
»»» anonymousbodyResourceIdnone
»»» anonymousbodystringnone

Enumerated Values

ParameterValue
» statusdisabled
» statusenabled
»» resourceapi_clients
»» resourceapi_keys
»» resourceevents
»» resourcequeues
»» resourcelisteners
»» resourcemessages
»» resourceschemas
»» resourcestats
»» resourcesubscriptions
»» accessread
»» accesswrite
»»» anonymous*

Responses

200 Response

{
  "api_key": "EPLPXwVOdhCxc4lylNpMeDM0_GhnCAZg3tFrWtZbb0cYQ7NCyRVfaN-O9rItf5kw",
  "_links": {
    "self": {
      "href": "https://api.discue.io/queues/180994c-b6b2-4d0e-b7ad-414716e83386/messages/8476f9ea-e457-4fed-8fbd-347a96237a96"
    }
  }
}

400 Response

{
  "title": "Bad Request",
  "status": 400
}

401 Response

{
  "title": "Unauthorized",
  "status": 401
}

402 Response

{
  "title": "Payment Required",
  "status": 402
}

403 Response

{
  "title": "Forbidden",
  "status": 403
}

404 Response

{
  "title": "Not Found",
  "status": 404
}

405 Response

{
  "title": "Method Not Allowed",
  "status": 405
}

406 Response

{
  "title": "Not Acceptable",
  "status": 406
}

409 Response

{
  "title": "Conflict",
  "status": 409
}

415 Response

{
  "title": "Unsupported Media Type",
  "status": 415
}

422 Response

{
  "title": "Unprocessable Entity",
  "status": 422
}

423 Response

{
  "title": "Locked",
  "status": 423
}

429 Response

{
  "title": "Too Many Requests",
  "status": 429
}

500 Response

{
  "title": "Internal Server Error",
  "status": 500
}

501 Response

{
  "title": "Not Implemented",
  "status": 501
}

503 Response

{
  "title": "Service Unavailable",
  "status": 503
}
StatusMeaningDescriptionSchema
200OKopen in new windowOkPostApiKeyResponse
400Bad Requestopen in new windowBad RequestInline
401Unauthorizedopen in new windowUnauthorizedInline
402Payment Requiredopen in new windowPayment RequiredInline
403Forbiddenopen in new windowForbiddenInline
404Not Foundopen in new windowNot FoundInline
405Method Not Allowedopen in new windowMethod Not AllowedInline
406Not Acceptableopen in new windowNot AcceptableInline
409Conflictopen in new windowConflictInline
415Unsupported Media Typeopen in new windowUnsupported Media TypeInline
422Unprocessable Entityopen in new windowUnprocessable EntityInline
423Lockedopen in new windowLockedInline
429Too Many Requestsopen in new windowToo Many RequestsInline
500Internal Server Erroropen in new windowInternal Server ErrorInline
501Not Implementedopen in new windowNot ImplementedInline
503Service Unavailableopen in new windowService UnavailableInline

Last Updated:
Contributors: Stefan Pfaffel