OpenShift - List projects using REST API
by
Jeremy Canfield |
Updated: January 08 2024
| OpenShift articles
This assumes you have used the REST API to obtain an OAuth bearer token. Let's say the bearer token is sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U.
Here is how you would list every namespace. The oc config view or oc get apiserver commands can be used to display the API Server URL (api.openshift.example.com in this example).
curl
--insecure
--request GET
--header "Accept: application/json"
--header "Authorization: Bearer sha256~0Rs__hPuXmBD3TJTXNDisC7wRBN-nrFnYTxgdBrFT-U"
--url "https://api.openshift.example.com:6443/api/v1/namespaces"
Something like this should be returned. In this example, the first namespace is "foo".
{
"kind": "NamespaceList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/namespaces",
"resourceVersion": "637674757"
},
"items": [
{
"metadata": {
"name": "foo",
"selfLink": "/api/v1/namespaces/foo",
"uid": "d0022a41-0165-4734-b468-948fa40a93a9",
"resourceVersion": "568396970",
"creationTimestamp": "2020-10-20T13:40:08Z"
Did you find this article helpful?
If so, consider buying me a coffee over at