Bluemix Cloud Foundry REST API

▼魔方 西西 提交于 2019-12-13 02:27:42

问题


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


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/37520248/bluemix-cloud-foundry-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!