These examples use curl to perform some basic API tasks with Varnish Controller. All output and
input is JSON-structured data. Full Swagger API documentation can be viewed by starting the api-gw
and visiting http://localhost:8002/docs/index.html. The
host and port (localhost:8002) are where the api-gw is listening.
curl -X POST -utest:test http://localhost:8002/api/v1/auth/login
curl** -X POST -utest:test http://localhost:8002/api/v1/auth/login -d '{"org": "myorg"}'
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/agents
curl -H "Authorization: Bearer <access_token>" "http://localhost:8002/api/v1/agents?name=*server*"
curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/agents/1 -d '{"Tags": [{"ID": 2}]}'
curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/agents/1 -d '{"Tags": []}'
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/files
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/files/1
curl -H "Authorization: Bearer <access_token>" -X DELETE http://localhost:8002/api/v1/files/1
curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/vclgroups/1/deploy
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/apilogs
curl -X POST -H "Authorization: Refresh <refresh_token>" localhost:8002/api/v1/auth/refresh
If an error occurs for a request, an error structure will be reported back. It will contain a trace
ID (used in the system logs from the processes) that can be used to trace the error from the API-GW
back to the agents. A human-readable error message and an errorKey that describes the scope of the
error is reported back.
Example:
$ curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/vclgroups/2/deploy
{"traceId":"1coNQFLrcGkVcSXrOtfs0VtG3Ua","errorKey":"deploy","errorMsg":"id 2 not found"}%
For API requests we allow filters and operators on those filters. To see the complete list of available filters, check the API-GW Swagger documentation. The API has support for starts with, ends with or contains filters, as well as any or all filters. The API also supports filtering on relationships.
Operators can be used to change the behavior of filters, for example it is useful to filter everything after a specific date or return all agents that have all or any of the following tags
The equal filter filters an exact match.
GET /api/v1/agents?name=agent // Returns all records where name matches 'agent'
GET /api/v1/agents?name[neq]=agent // Returns all records where name matches 'agent'
GET /api/v1/agents?name[neq]=*agent* // Returns all records where name does not contain 'agent'
GET /api/v1/agents?name[neq]=*agent*,*varnish // Returns all records where name does not contain 'agent' and do not end with 'varnish'
GET /api/v1/agents?tags.id[neq]=1,2 // Returns all records that do not have a connected tag with id 1 OR 2
GET /api/v1/agents?name=agent* // Returns all records where name starts with 'agent'
GET /api/v1/agents?name=*agent // Returns all records where name ends with 'agent'
GET /api/v1/agents?name=*agent* // Returns all records where name contains 'agent'
GET /api/v1/agents?name=*agent*,*varnish // Returns all records where name contains 'agent' and that do not end with 'varnish'
GET /api/v1/agents?tags.id=1,2 // Returns all records that have a connected tag with id 1 OR 2
GET /api/v1/agents?tags.id[all]=1,2 // Returns all records that have a connected tag with id 1 AND 2
GET /api/v1/agents?created[gt]=2020-11-01 // Returns all records where created at is greater than
GET /api/v1/agents?created[gte]=2020-11-01 // Returns all records where created at is greater than or equal to
GET /api/v1/agents?created[lt]=2020-11-01 // Returns all records where created at is lower than
GET /api/v1/agents?created[lte]=2020-11-01 // Returns all records where created at is lower than or equal to