0

I am trying to use IBM CAM's ReST API but I get 401 Unauthorised error. How to I generate the authorization token to authorize to access the resources?

codec
  • 7,978
  • 26
  • 71
  • 127

1 Answers1

0

Get access token from Bluemix

You can do a POST to:

https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token

with headers:

Content-Type : application/x-www-form-urlencoded 
Authorization : Basic Y2Y6
Accept : application/json

and body:

grant_type=password&username={yourusername}&password={yourpassword}

this will return you JSON containing an access_token

Copy that access token and you can use it in your calls to Cloud Automation Manager (CAM) APIs as a bearer token

Use token with Cloud Automation Manager

Sample API call to CAM to retrieve a list of deployments (Stacks):

https://cam-proxy-ng.ng.bluemix.net/cam/api/v1/Stacks?cloudOE_spaceGuid={spaceuuid}&ace_orgGuid={orguuid}&tenantId={tenantuuid}

Where you can get spaceuuid, orguuid and tenantuuid from your browser cookies under cam-proxy-dev.ng.bluemix.net Note: remove any "%22" from the data at the beginning and end of the uuid of the cookie data.

with headers:

Authorization : bearer <accesstoken>

You can see more APIs listed here https://cam-api-explorer.mybluemix.net/#/

hhockett
  • 51
  • 3
  • I could get the token but coudn't get response for GET API `https://cam-proxy-ng.ng.bluemix.net/cam/api/v1/cloudconnections` with `Authorization=Bearer ASDJHLD....` header. I got 401. – codec Jun 16 '17 at 11:51
  • Hello, at the end of the API have you also included the spaceuuid, orguuid and tenantId? like this /cloudconnections?cloudOE_spaceGuid={spaceuuid}&ace_orgGuid={orguuid}&tenantId={tenantuuid} Note: you can retrieve these uuids from your browser cookies when logged into the UI. Are you seeing an error? or perhaps no response? – hhockett Jun 17 '17 at 12:51
  • note: I think I also see a space in your cloudconnecti‌​ons between the i and o when I copy/paste it (could just be how it was pasted on this site) – hhockett Jun 18 '17 at 03:24
  • I do not see these cookies in the browser cache. I am using Chrome browser. – codec Jun 22 '17 at 12:34