Bluemix Cloud Foundry REST API

2019-07-29 05:04发布

Can I access Cloud Foundry REST API on Bluemix? If yes, how can I access it (cannot find any documentation)?

2条回答
不美不萌又怎样
2楼-- · 2019-07-29 05:23

In order to access CF API you have to get the authentication token. Then add it to each request in the headers.

oauthTokenResponse = requests.post(
  f'https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token?grant_type=password&client_id=cf',
  data={'username': <your username>, 'password': <your password>, 'client_id': 'cf'},
  auth=('cf', '')
)
auth = oauthTokenResponse.json()['token_type'] + ' ' + oauthTokenResponse.json()['access_token']

appsResponse = requests.get(f'{self.api_endpoint}/v2/apps',
  headers={'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth}
)

apps = json.loads(appsResponse.content)
查看更多
我命由我不由天
3楼-- · 2019-07-29 05:31

You can access the Cloud Foundry REST API on Bluemix as you would normally do with CF. In addition to that, if you need it and you are already familiar with cf curl you can take a look at the bluemix curl command. For example if you want to retrieve the information for all organizations of the current account:

bluemix curl /v2/organizations

Please see the Docs for more information.

查看更多
登录 后发表回答