github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/commands/operator/api.mdx (about) 1 --- 2 layout: docs 3 page_title: 'Commands: operator api' 4 description: | 5 operator api is a utility command for accessing Nomad's HTTP API similar to 6 the popular open source program curl. 7 --- 8 9 # Command: operator api 10 11 The `operator api` command allows easy access to Nomad's HTTP API similar to 12 the popular [curl] program. Nomad's `operator api` command reads [environment 13 variables][envvars] to dramatically ease HTTP API access compared to trying to 14 manually write the same command with the third party `curl` command. 15 16 For example for the following environment: 17 18 ``` 19 NOMAD_TOKEN=d4434353-c797-19e4-a14d-4068241f86a4 20 NOMAD_CACERT=$HOME/.nomad/ca.pem 21 NOMAD_CLIENT_CERT=$HOME/.nomad/cli.pem 22 NOMAD_CLIENT_KEY=$HOME/.nomad/client-key.pem 23 NOMAD_TLS_SERVER_NAME=client.global.nomad 24 NOMAD_ADDR=https://remote.client123.internal:4646 25 ``` 26 27 Accessing Nomad's [`/v1/jobs`][jobs] HTTP endpoint with `nomad operator 28 api` would require: 29 30 ``` 31 nomad operator api /v1/jobs 32 ``` 33 34 Performing the same request using the external `curl` tool would require: 35 36 ``` 37 curl \ 38 --cacert "$HOME/.nomad/ca.pem" \ 39 --cert "$HOME/.nomad/client.pem" \ 40 --key "$HOME/.nomad/client-key.pem" \ 41 --connect-to "client.global.nomad:4646:remote.client123.internal:4646" \ 42 -H "X-Nomad-Token: ${NOMAD_TOKEN}" \ 43 https://client.global.nomad:4646/v1/jobs 44 ``` 45 46 ## General Options 47 48 @include 'general_options.mdx' 49 50 ## Operator API Options 51 52 - `-dryrun`: output a curl command instead of performing the HTTP request 53 immediately. Note that you do *not* need the 3rd party `curl` command 54 installed to use `operator api`. The `curl` output from `-dryrun` is intended 55 for use in scripts or running in locations without a Nomad binary present. 56 57 - `-filter`: Specifies an expression used to filter query results. 58 59 - `-H`: Adds an additional HTTP header to the request. May be specified more 60 than once. These headers take precedence over automatically set ones such as 61 X-Nomad-Token. 62 63 - `-verbose`: Output extra information to stderr similar to curl's --verbose 64 flag. 65 66 - `-X`: HTTP method of request. If there is data piped to stdin, then the 67 method defaults to POST. Otherwise the method defaults to GET. 68 69 ## Examples 70 71 ```shell-session 72 $ nomad operator api -verbose /v1/agent/members?pretty 73 > GET http://127.0.0.1:4646/v1/agent/members?pretty= 74 * Sending request and receiving response... 75 < HTTP/1.1 200 OK 76 < Date: Wed, 02 Mar 2022 01:10:59 GMT 77 < Content-Type: application/json 78 < Vary: Accept-Encoding 79 { 80 "Members": [ 81 ... 82 83 84 $ nomad operator api -region eu-west -filter 'Status == "completed"' -dryrun /v1/evaluations 85 curl \ 86 -X GET \ 87 http://127.0.0.1:4646/v1/evaluations?filter=.Status+%3D%3D+%22completed%22®ion=eu-west 88 ``` 89 90 91 92 93 [curl]: https://curl.se/ 94 [envvars]: /docs/commands#environment-variables 95 [jobs]: /api-docs/jobs