deerstalker
deerstalker

Reputation: 31

Is there a sample code for using IBM Bluemix Container API?

I'm trying to create container in bluemix with API as it in http://ccsapi-doc.mybluemix.net In the document it mentions:

When using the API with the new model, the following HTTP headers shall be provided: X-Auth-Token = Bluemix JWT Token X-Auth-Project-Id = Space GUID

But I have no idea how to get or generate the Bluemix JWT Token. Can someone help me ?

Upvotes: 1

Views: 482

Answers (3)

Crescenzo Migliaccio
Crescenzo Migliaccio

Reputation: 1249

This is an alternative Method:

You can retrieve X-Auth-Token and X-Auth-Project-Id with this command:

cf login
CF_TRACE=true cf ic login

Copy all output in a .txt file and search for X-Auth-Token and X-Auth-Project-Id

here there is a simple example:

curl -X GET --header "Accept: application/json" --header "X-Auth-Token: asdlkfajdfdkaldkjfskl239049283049jsdfjksl29304" --header "X-Auth-Project-Id: sdfadf-0090-43ef-22932-23434234" "https://containers-api.ng.bluemix.net/v3/containers/quota"


Response:
The output of API is like this:
{
  "account_type": "TRIAL",
  "country_code": "ITA",
  "org_quota": {
    "floating_ips_max": "2",
    "floating_ips_space_default": "2",
    "floating_ips_usage": 2,
    "ram_max": "2048",
    "ram_space_default": "2048",
    "ram_usage": 2048,
    "subnet_usage": -1,
    "subnets_default": "5",
    "subnets_max": 0
  },
  "space_quota": {
    "floating_ips_max": 2,
    "ram_max": 2048,
    "subnets_max": -1
  }

Upvotes: 0

Kyungmo Jung
Kyungmo Jung

Reputation: 71

You can get X-Auth-Token by cf oauth-token command. Then copy and paste rest of the part after bearer. And you also can get X-Auth-Project-Id by cf space --guid <space Name>. Please see below commands;

$ cf login -a api.<region>.bluemix.net -u <space name> -o <org name> -s <space name>

$ cf ic login

$ cf oauth-token

$ cf space <space-name> --guid (space name where the container exists)

Upvotes: 4

ValerieLampkin
ValerieLampkin

Reputation: 2626

Try expanding the Authentication section on that page and the "Get TLS Certificate" to show more info

enter image description here

When you enter the values and click "try it out" you will see additional output generated with token info.

Upvotes: 0

Related Questions