API7 Docs

Create a consumer credential on a gateway group

POST /apisix/admin/consumers/{username}/credentials

POST /apisix/admin/consumers/{username}/credentials

Interactive request editor loads with JavaScript.

Authorization

X-API-KEY<token>

In: header

Path Parameters

username*string

The unique identifier of the consumer.

Match^[a-zA-Z0-9_\-]+$
Length1 <= length <= 512

Query Parameters

gateway_group_id*string

Gateway group ID. Optional when using the gateway group admin key to authenticate.

Length1 <= length

Request Body

application/json

The consumer credential description.

Response Body

application/json

application/json

curl -X POST "$API_BASE_URL/apisix/admin/consumers/johndoe/credentials?gateway_group_id=86fb9981-d9d2-4555-9df8-91ae92129335" \  -H "Content-Type: application/json" \  -d '{    "name": "us-west-rsc",    "plugins": {      "key-auth": {}    }  }'

Consumer credential created successfully.

{
  "value": {
    "name": "us-west-rsc",
    "plugins": {
      "key-auth": {
        "key": "john-key"
      }
    },
    "desc": "Object description.",
    "labels": {
      "version": "v2",
      "env": "prod"
    },
    "id": "bd58fce2-b6cc-4d2d-a53c-6ce11b19c101",
    "created_at": 1742288232,
    "updated_at": 1742288235
  }
}
Complete operation details and schema variants

POST /apisix/admin/consumers/{username}/credentials

Create a consumer credential on a gateway group

IAM Action: gateway:CreateConsumerCredential, Resource: arn:api7:gateway:gatewaygroup/%s/consumer/%s

Parameters

  • username (path, string, required): The unique identifier of the consumer.
  • gateway_group_id (query, string, required): Gateway group ID. Optional when using the gateway group admin key to authenticate.

Request body

Content type: application/json

  • name (string, required): The object name.
  • plugins (object, required): Plugin configuration.
  • oneOf variant 1: key-auth
  • plugins.key-auth (object, required): key-auth plugin configurations.
  • plugins.key-auth.key (string, optional): key-auth user key.
  • oneOf variant 2: basic-auth
  • plugins.basic-auth (object, required): basic-auth plugin configurations.
  • plugins.basic-auth.username (string, optional): basic-auth unique username.
  • plugins.basic-auth.password (string, optional): basic-auth user password.
  • oneOf variant 3: hmac-auth
  • plugins.hmac-auth (object, required): hmac-auth plugin configurations.
  • plugins.hmac-auth.key_id (string, optional): hmac-auth key unique identifier.
  • plugins.hmac-auth.secret_key (string, optional): hmac-auth secret key.
  • oneOf variant 4: jwt-auth
  • plugins.jwt-auth (object, required): jwt-auth plugin configurations.
  • plugins.jwt-auth.key (string, optional): jwt-auth key unique identifier.
  • plugins.jwt-auth.secret (string, optional): jwt-auth secret.
  • oneOf variant 5: ldap-auth-advanced
  • plugins.ldap-auth-advanced (object, required): ldap-auth-advanced plugin configurations.
  • plugins.ldap-auth-advanced.user_dn (string, optional): ldap-auth-advanced unique user DN.
  • desc (string, optional): The object description.
  • labels (object, optional): Key-value pairs of labels.

Responses

  • 200: Consumer credential created successfully.
  • allOf variant 1
  • value (object, optional): The specific resource.
  • allOf variant 2
  • value (object, optional): The consumer credential with management fields.
  • allOf variant 1
  • value.name (string, required): The object name.
  • value.plugins (object, required): Plugin configuration.
  • oneOf variant 1: key-auth
  • value.plugins.key-auth (object, required): key-auth plugin configurations.
  • value.plugins.key-auth.key (string, optional): key-auth user key.
  • oneOf variant 2: basic-auth
  • value.plugins.basic-auth (object, required): basic-auth plugin configurations.
  • value.plugins.basic-auth.username (string, optional): basic-auth unique username.
  • value.plugins.basic-auth.password (string, optional): basic-auth user password.
  • oneOf variant 3: hmac-auth
  • value.plugins.hmac-auth (object, required): hmac-auth plugin configurations.
  • value.plugins.hmac-auth.key_id (string, optional): hmac-auth key unique identifier.
  • value.plugins.hmac-auth.secret_key (string, optional): hmac-auth secret key.
  • oneOf variant 4: jwt-auth
  • value.plugins.jwt-auth (object, required): jwt-auth plugin configurations.
  • value.plugins.jwt-auth.key (string, optional): jwt-auth key unique identifier.
  • value.plugins.jwt-auth.secret (string, optional): jwt-auth secret.
  • oneOf variant 5: ldap-auth-advanced
  • value.plugins.ldap-auth-advanced (object, required): ldap-auth-advanced plugin configurations.
  • value.plugins.ldap-auth-advanced.user_dn (string, optional): ldap-auth-advanced unique user DN.
  • value.desc (string, optional): The object description.
  • value.labels (object, optional): Key-value pairs of labels.
  • allOf variant 2
  • value.id (string, optional): The object ID.
  • value.created_at (integer, optional): The object created timestamp.
  • value.updated_at (integer, optional): The object updated timestamp.
  • 400: Bad Request — The request was malformed or contained invalid parameters. Check the error_msg field for details.
  • value (object, optional): The specific resource.
  • error_msg (string, optional): The error message.

cURL

curl -X POST '$API_BASE_URL/apisix/admin/consumers/{username}/credentials'