IBM Cloud Global

 View Only

Using Cloud Foundry APIs on IBM Cloud

By INDIRA KALAGARA posted Mon December 07, 2020 01:07 AM

  


Using CloudFound APIs on IBM Cloud:

To work with the IBM Cloud Services we mostly use the IAM API Keys or Access tokens to authenticate first. In similar way  to work with Cloud Foundry (CF) applications  and services of  IBM Cloud using either cli or API ,  we have to authenticate first against the logging server and then perform the corresponding actions.  Although  this looks a straight forward approach, I had come across a bit of difficulty in finding the way to retrieve the CF authentication token using API so that I can retrieve the list of applications. So here I am sharing the instructions which I have followed. 

To start with :

        Make sure the user has Cloud Foundry Access
        Ensure to create IAM API Key on IBM Cloud Console 
        Find the API end-points for the CF api end-points to authenticate


Retrieve Access Token using API

Using the Login server API Endpoint , retrieve the CF auth token.  Make sure to set the region based on the IBM Cloud region where the CF applications are being deployed

https://iam.cloud.ibm.com/cloudfoundry/login/<REGION>/oauth/token'


Example command

curl -u "cf:" -X POST '<REPLACE_LOGIN_SERVER_API_ENDPOINT> ' --data-urlencode 'grant_type=password' --data-urlencode 'username=apikey'  --data-urlencode 'password=<API_KEY_Value>'

 
Replace the REPLACE_LOGIN_SERVER_API_ENDPOINT with following entry for region us-south and replace the API Key value for the password

Example:

 curl -u "cf:" -X POST 'https://iam.cloud.ibm.com/cloudfoundry/login/us-south/oauth/token' --data-urlencode 'grant_type=password' --data-urlencode 'username=apikey'  --data-urlencode 'password=xxxxxxxxxxxxxxx'

  Set Authorization header:

            Basic-Auth:

                username : “cf:"

Set Body Parameters:

            'grant_type=password'

             'username=apikey’

            'password=<API_KEY_Value>'

 


Retrieve Access Token using CLI Command

 
       1. Login to IBM Cloud

          ibmcloud login

            set Org , space ,resource group

       2. Set CF API endpoint

            ibmcloud target --cf-api api.us-south.cf.cloud.ibm.com
       
      3. Get CF Auth token

            ibmcloud cf oauth-token

 

Now, using the Access token from above, 

Retrieve the List of Cloud Foundry Apps

Api end-point to retrieve the applications:
     https://api.us-south.cf.cloud.ibm.com/v3/apps/

 

curl --location --request GET 'https://api.us-south.cf.cloud.ibm.com/v3/apps/' \

> --header 'Authorization: Bearer xxxxxxxxxxx'

Output:

{

  "pagination": {

    "total_results": 39,

....

  },

  "resources": [

    {

      "guid": "3de3344a-2fca-41b7-b3bf-11ecb6294e25",

      "created_at": "2015-12-07T09:37:55Z",

      "updated_at": "2019-08-16T15:44:16Z",

      "name": "XMLToDBBP",

      "state": "STOPPED",

      "lifecycle": {

        "type": "buildpack",

        "data": {

          "buildpacks": [

…….

}

 






0 comments
239 views

Permalink