2016-05-30 144 views

回答

3

您可以像訪問CF一樣使用Bluemix上的Cloud Foundry REST API。除此之外,如果您需要它並且您已經熟悉cf curl,則可以查看bluemix curl命令。例如,如果你想獲取信息當前帳戶的所有組織:

bluemix curl /v2/organizations 

請參閱Docs以獲取更多信息。

+0

非常感謝。我現在可以使用https://api.eu-gb.mybluemix.net/v2/info訪問CF API。它檢索URL以獲取認證令牌(POST https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token)。然後通過令牌,我可以與CF REST API進行交互。 – edevregille

0

爲了訪問CF API,您必須獲取身份驗證令牌。然後將其添加到標題中的每個請求。

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)