c8y(1)

πŸ“¦ version 2.56.1, in nixpkgs unstable

hiii bestie πŸ’– welcome to the c8y(1) manual page β€” specifically the c8y api command, and yes it’s giving main character energy. We’re sending authenticated API requests, keeping every flag, and not skipping a single detail. periodt ✨


🌸 NAME 🌸

c8y-api β€” send api request


πŸ¦‹ SYNOPSIS πŸ¦‹

c8y api [flags]

✨ DESCRIPTION ✨

Sends an authenticated API request to the endpoint you give it. That’s the whole vibe: you point, it sends, slay πŸ’…


πŸŽ€ OPTIONS πŸŽ€

  • --accept="" β€” accept (header)
  • --contentType="" β€” content type (header)
  • -d, --data=[] β€” static data that gets applied to the body; accepts JSON or shorthand JSON, i.e. --data 'value1=1,my.nested.value=100'
  • --file="" β€” file to be uploaded as a binary
  • --formdata="" β€” form data (JSON or shorthand JSON)
  • -h, --help[=false] β€” help for api
  • --host="" β€” host to use for the REST request; if it’s empty, then the session’s host will be used
  • --keepProperties[=true] β€” don’t strip Cumulocity properties from the data property, i.e. source etc.
  • --method="GET" β€” HTTP method
  • --template="" β€” body template
  • --templateVars=[] β€” body template variables
  • --url="" β€” URL path; any reference to '%s' will be replaced with the current input value (accepts pipeline)

🫢 OPTIONS INHERITED FROM PARENT COMMANDS 🫢

No gatekeeping here β€” these come from the parent commands and they’re all still part of the menu, bestie:

  • --abortOnErrors=10 β€” abort batch when reaching the specified number of errors
  • --allowEmptyPipe[=false] β€” don’t fail when piped input is empty (stdin)
  • --cache[=false] β€” enable cached responses
  • --cacheBodyPaths=[] β€” cache should limit hashing of selected paths in the JSON body; empty indicates all values
  • --cacheTTL="60s" β€” cache time-to-live (TTL) as a duration, i.e. 60s, 2m
  • -c, --compact[=false] β€” compact instead of pretty-printed output when using JSON output; pretty print is the default if output is the terminal
  • --confirm[=false] β€” prompt for confirmation
  • --confirmText="" β€” custom confirmation text
  • --currentPage=0 β€” current page which should be returned
  • --customQueryParam=[] β€” add custom URL query parameters, i.e. --customQueryParam 'withCustomOption=true,myOtherOption=myvalue'
  • --debug[=false] β€” set very verbose log messages
  • --delay="0ms" β€” delay after each request, i.e. 5ms, 1.2s
  • --delayBefore="0ms" β€” delay before each request, i.e. 5ms, 1.2s
  • --dry[=false] β€” dry run; don’t send any data to the server
  • --dryFormat="markdown" β€” dry run output format, i.e. json, dump, markdown or curl
  • --examples[=false] β€” show examples for the current command
  • --filter=[] β€” apply a client-side filter to the response before returning it to the user
  • --flatten[=false] β€” flatten JSON output by replacing nested JSON properties with properties where their names are represented by dot notation
  • -f, --force[=false] β€” do not prompt for confirmation; ignored when using --confirm
  • -H, --header=[] β€” custom headers, i.e. --header "Accept: value, AnotherHeader: myvalue"
  • --includeAll[=false] β€” include all results by iterating through each page
  • -k, --insecure[=false] β€” allow insecure server connections when using SSL
  • -l, --logMessage="" β€” add custom message to the activity log
  • --maxJobs=0 β€” maximum number of jobs; 0 = unlimited (use with caution!)
  • --noAccept[=false] β€” ignore the Accept header; this will remove the Accept header from requests, however PUT and POST requests will only see the effect
  • --noCache[=false] β€” force disabling of cached responses (overwrites cache setting)
  • -M, --noColor[=false] β€” don’t use colors when displaying log entries on the console
  • --noLog[=false] β€” disables the activity log for the current command
  • --noProgress[=false] β€” disable progress bars
  • --noProxy[=false] β€” ignore the proxy settings
  • -n, --nullInput[=false] β€” don’t read the input (stdin); useful if using in shell for/while loops
  • -o, --output="table" β€” output format, i.e. table, json, csv, csvheader
  • --outputFile="" β€” save JSON output to file (after select/view)
  • --outputFileRaw="" β€” save raw response to file (before select/view)
  • --outputTemplate="" β€” jsonnet template to apply to the output
  • -p, --pageSize=5 β€” maximum results per page
  • --progress[=false] β€” show progress bar; this will also disable any other verbose output
  • --proxy="" β€” proxy setting, i.e. http://10.0.0.1:8080
  • -r, --raw[=false] β€” show raw response; this mode will force output=json and view=off
  • --retries=3 β€” max number of attempts when a failed HTTP call is encountered
  • --select=[] β€” comma-separated list of properties to return; wildcards and globstar accepted, i.e. --select 'id,name,type,**.serialNumber'
  • --session="" β€” session configuration
  • --sessionMode="" β€” override default session mode for a single command which would normally be disabled
  • -P, --sessionPassword="" β€” override session password
  • -U, --sessionUsername="" β€” override session username, i.e. peter or t1234/peter (with tenant)
  • --silentExit[=false] β€” silent status codes do not affect the exit code
  • --silentStatusCodes="" β€” status codes which will not print out an error message
  • --timeout="600s" β€” request timeout duration, i.e. 60s, 2m
  • --totalPages=0 β€” total number of pages to get
  • -v, --verbose[=false] β€” verbose logging
  • --view="auto" β€” use views when displaying data on the terminal; disable using --view off
  • --withError[=false] β€” errors will be printed on stdout instead of stderr
  • --withTotalElements[=false] β€” request Cumulocity to include the total elements in the response statistics under .statistics.totalElements (introduced in 10.13)
  • -t, --withTotalPages[=false] β€” request Cumulocity to include the total pages in the response statistics under .statistics.totalPages
  • --workers=1 β€” number of workers

🌈 EXAMPLE 🌈

Okay bestie, examples are where it gets iconic. Here’s every single one, no skips:

$ c8y api GET /alarm/alarms

Get a list of alarms ✨

$ c8y api GET "/alarm/alarms&status=ACTIVE" --pageSize 10

Get a list of alarms with custom query parameters.

$ c8y api GET "/dosomething" --host localhost:8080

Send a GET request to a custom hosted service running on localhost port 8080. You can force https or http by adding them as a prefix to the host.

$ c8y api GET "/dosomething" --host $C8Y_HOST/service/mymicroservice --dry

Send a request to a microservice hosted in the cloud. The /dosomething will be appended to the /service/mymicroservice path provided by the host flag. Results in the following request: GET /service/mymicroservice/dosomething sent to the current session URL.

$ c8y api GET "/alarm/alarms&status=ACTIVE" --pageSize 1 --withTotalPages

Get a total ACTIVE alarms.

$ c8y api POST "alarm/alarms" --data "text=one,severity=MAJOR,type=test_Type,time=2019-01-01,source.id='12345'" --keepProperties

Create a new alarm.

$ c8y activitylog list --filter "method like POST" | c8y api --method DELETE

Get items created via POST from the activity log and delete them.

$ echo -e "/inventory/1111\n/inventory/2222" | c8y api --method PUT --template "{myScript: {lastUpdated: _.Now() }}"

Pipe a list of urls and execute HTTP PUT and use a template to generate the body.

$ echo "12345" | c8y api PUT "/service/example" --template "{id: input.value}"

Send a PUT request to a fixed url, but use the piped input to build the request’s body.

$ echo "12345" | c8y api PUT "/service/example/%s" --template "{id: input.value}"

Send a PUT request using the piped input in both the url and the request’s body ('%s' will be replaced with the current piped input line).

$ echo "{\"url\": \"/service/custom/endpoint\",\"body\":{\"name\": \"peter\"}}" | c8y api POST --template "input.value.body"

Build a custom request using piped json. The input url property will be mapped to the --url flag, and use a template to also build the request’s body from the piped input data.


πŸ’œ SEE ALSO πŸ’œ


okay that’s the whole page bestie β€” stamped Jan 1980 and filed under c8y(1). now go make some authenticated API requests, slay πŸ’…βœ¨

πŸ“¦ where this page comes from