Objective of this article to know how to call REST API from CLI to get the projects list. Continue further to know various problems and solutions to overcome and finally list the projects.
How to call REST API from CLI?
To call REST API from CLI, we can use curl -k command followed by the REST URL. For more information look at the below command,
How to solve Forbidden (403) issue while calling REST API?
Since we are not authorized who is calling the API, we end up with the problem of 403 Forbidden. To solve this problem, login as developer by using the following command.
oc login -u developer -p developer
Then issue the below command to get the security token which we need to pass in REST API call.
oc whoami -t
Now pass the security key in the REST call Authorization by using -H “Authorization: Bearer PaqE4Ui1mirlpAUqi6w-20VQS0qeD3EXA8w1IhwewqE”. The complete URL looks like,
curl -k https://192.168.99.100:8443/oapi/v1/projects -H “Authorization: Bearer PaqE4Ui1mirlpAUqi6w-20VQS0qeD3EXA8w1IhwewqE”
Below image will show you what is the response we will get when we have already created project in OpenShift.