Getting started with the Cloud Foundry API

So this week I started tinkering with the cloud foundry API. In all honesty I did have to get a little help from one of our developers because I was doing something wrong. Forgetting that in my lab I don’t have trusted certificates I wasn’t using a flag in the headers below to ignore that. Anyway just a slight glitch.

First you need to get your endpoint URL by asking for info from your CF API


Get Endpoint:

Get https://API.pcfsys.domain.local/info

This should give you a payload with the endpoint listed. Using the endpoint url now post a payload like the one below substituting your domain and your admin user/password.


Get token:

POST https://login.pcfsys.domain.local/oauth/token




Authorization:Basic Y2Y6








At this point you should be presented with payload with your access token listed. Now you can use the access token to Get stuff. Like a list of the CF orgs.


List orgs:

Get https://API.pcfsys.domain.local/v2/organizations



Authorization:bearer eyJhbGciOiJSUzI1…………..


List Spaces:

Get https://API.pcfsys.domain.local/v2/spaces

Headers = same as orgs


List Apps:

Get https://API.pcfsys.domain.local/v2/apps

Headers = same as orgs


List Users:

Get https://API.pcfsys.domain.local/v2/users

Headers = same as orgs


OK how about something a bit more like a query? How about we list all the space for a given user?

When you called the list of users you should be presented with a payload that also includes the guid for each user. Using this guid you can list the spaces for that user.


List spaces for specific user using the guid:

Get https://API.pcfsys.domain.local/v2/users/94aa5e3b-86e1-4ca0-90b1-4734d6555ef2/spaces

Headers = same as orgs


Simple right… watch this space for more on the Cloud Foundry API