KBEC-00433 - Test Flow REST API with curl

Problem

Using the CloudBees Flow REST API explains Flow REST API in details. However, you  may need to access Flow REST API in some cases that the doc does not cover. For example, you may need to access it in command line to test it or get some data from the Flow server from a machine where ectool/ec-perl is not available.

Solution

You can use the curl tool  to access the Flow server REST API. Here're some tips.

Using the "-k" option to work around SSL certificate problem

You may get the error "curl: (60) SSL certificate problem: self signed certificate" like what happens in the following case:

HuafengsMac:174678 huafeng$ curl -X GET --header "Accept: application/json" "https://flowserver/rest/v1.0/server/info"
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
HuafengsMac:174678 huafeng$

You can use the "-k" option like the following example:

HuafengsMac:174678 huafeng$ curl -k -X GET --header "Accept: application/json" "https://flowserver/rest/v1.0/server/info"
{"serverInfo":{"cluster":"0","httpPort":"8000","httpsPort":"8443","jobEventsDestination":"/topic/events.job","jobEventsSelector":"path = '/jobs/$[jobId]'","putFileDestination":"/queue/jobs.$[jobId]","putFileSelector":"command='PUT_FILE' AND channel='$[channel]'","stompClientUri":"stomp+ssl://flowserver:61613"}}
HuafengsMac:174678 huafeng$

Using the "-u" option to set credentials to access the Flow server

Please note that the API "getServerInfo" in the previous example is an API that does not require the caller has access right to the Flow server. Most of the Flow REST APIs do require the caller has access right to the Flow server. For example:

HuafengsMac:174678 huafeng$ curl -k -X GET --header "Accept: application/json" "https://flowserver/rest/v1.0/licenses"
{"error":{"where":"","message":"No credentials/session found in this request","details":"","code":"NoCredentials"}}
HuafengsMac:174678 huafeng$

You can use the "-u" option to provide the credentials like the following example:

HuafengsMac:174678 huafeng$ curl -k -u admin:<PASSWORD> -X GET --header "Accept: application/json" "https://flowserver/rest/v1.0/licenses"
{"license":[{"licenseId":"cd00da46-e03e-11e9-9e41-de4420524153","productName":"ElectricCommander","createTime":"2019-09-26T09:19:53.786Z","customerName":"Electric Cloud, Inc.","evaluation":"0","featureName":"Server","gracePeriod":"0","lastModifiedBy":"admin","modifyTime":"2019-09-26T09:19:53.786Z","owner":"admin","signature":"<HIDDEN>","propertySheet":{"propertySheetId":"cd00da47-e03e-11e9-9e41-de4420524153","createTime":"2019-09-26T09:19:53.786Z","credentialProtected":"0","lastModifiedBy":"admin","modifyTime":"2019-09-26T09:19:53.786Z","owner":"admin","tracked":"0","property":[{"propertyId":"cd2244f8-e03e-11e9-9e41-de4420524153","propertyName":"editionName","createTime":"2019-09-26T09:19:53.786Z","expandable":"1","lastModifiedBy":"admin","modifyTime":"2019-09-26T09:19:53.786Z","owner":"admin","suppressValueTracking":"0","tracked":"0","value":"standard"},{"propertyId":"cd2bbad9-e03e-11e9-9e41-de4420524153","propertyName":"maxConcurrentSteps","createTime":"2019-09-26T09:19:53.786Z","expandable":"1","lastModifiedBy":"admin","modifyTime":"2019-09-26T09:19:53.786Z","owner":"admin","suppressValueTracking":"0","tracked":"0","value":"2"}]}}]}
HuafengsMac:174678 huafeng$

Please note that the password in the command and the signature in the output are replaced by "<PASSWORD>" and "<HIDDEN>"

Have more questions?

0 Comments

Article is closed for comments.