Bootstrap FreeKB - Kong Community Edition (KongCE) - List consumers using REST API
Kong Community Edition (KongCE) - List consumers using REST API


A consumer is typically thought of as a person that has been associated with one or more plugins, as a way to allow a request to be submitted to a route and then onto a service. For example, a consumer could be associated wtih the API Key and ACL Group plugins, so that the consumer must present a certain API Key and be a member of the ACL group to be allowed to submit a request onto the route and then onto the service.

 

The curl GET command can be used to list Consumers.


On the Kong server

If Kong is running on docker, refer to Kong - Docker container command line for the steps on how to issue commands in the Kong Docker container. Assuming you are using the default kong.conf file, the Kong Admin API will listen on port 8001.

If issuing this command on the Kong server, this command will display Consumer JSON.

curl -X GET "http://localhost:8001/consumers"

 

This command will display a specific Consumer.

curl -X GET "http://localhost:8001/consumers/consumer_name_or_id"

 


From a remote server

If issuing this command from a remote server, this command will display Consumer JSON.

curl -X GET "http://hostname:8000/admin-api/consumers"

 

This command will display a specific Consumer.

curl -X GET "http://hostname:8000/admin-api/consumers/consumer_name_or_id"

 


If there are no Consumers, something like this will be displayed.

{
 "message":"Not Found"
}

 

If there are Consumers, something like this will be displayed.

{
 "custom_id":null
 "created_at":1583244607
 "id":"a51b05c4-fc81-4552-88a0-17842065e8b2"
 "tags":null
 "username":"john.doe"
}

 


100 results

Only the first 100 Consumers will be returned, starting with the Consumer that has the lowest numeric ID, and then ascending. The output will include offset, like this.

"offset":"WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"

 

In this example, you would use the offset to return the next 100 records.

curl -X GET "http://hostname:8000/admin-api/consumers?offset=WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"

 

When there are no more records, offset will not be included in the output, like this.

  {  
   "custom_id":null
   "created_at":1565816518
   "id":"ffb481c2-a3d9-4b14-9a59-022ca4cda18d"
   "tags":null
   "username":"john.doe"
  }
 ]
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter a801b5 in the box below so that we can be sure you are a human.