Using cURL with Metacloud

The curl command-line tool lets you interact with your Metacloud environment to transfer data and make API requests. First, you must use your credentials to request the Identity service to provide a token for authenticating API requests.

You can reference environment variables that were applied by the openrc.sh file, but you must indicate the version in the URL you provide: $OS_AUTH_URL/v3/ It is also important to include the DOMAIN_ID when making a request to the Identity v3 API.

When constructing the curl POST command, you need to include the following data (option -d):

  • auth object
  • identity object
  • methods—specify the password method
  • user—user credentials
    • name—your username; you can use id instead
    • domain—include the domain id
    • password—the password that corresponds to the name

To request a token:

$ curl -k -i -X POST -H "Content-Type: application/json" \
   -d '   
    {"auth": 
       {"identity": 
           {"methods": ["password"],"password": 
               {"user": 
                  {"name": "<USERNAME>",
                   "domain": { "id": "<DOMAIN_ID>" },
                   "password": "<USER_PASSWORD>"
                   }
                }
            }
        }
    }' https://<API-AZ.METACLOUD.NET>:5000/v3/auth/tokens

The following uses the environment variables defined in the openrc.sh file so you can cut and paste to your CLI:

curl -k -i -X POST -H "Content-Type: application/json" -d '{"auth": {"identity": {"methods": ["password"], "password": {"user": {"name": "'"$OS_USERNAME"'", "domain": {"id": "'"$OS_USER_DOMAIN_ID"'"}, "password": "'"$OS_PASSWORD"'"}}}}}' "$OS_AUTH_URL"/v3/auth/tokens

Responses

If the curl request is successful, you receive a 200 code followed by the details that you requested. The following is a list of common code responses to help with troubleshooting:

  • 200—Success
  • 401 Unauthorized—Access is denied; check your authentication credentials.
  • 404 Not Found—Resource not found; check the endpoint.

The following is a truncated response to the above token request.

HTTP 201 Created

Server: Apache Python/2.7.5
Content-Type: application/json
X-Subject-Token: <TOKEN>

{
  "token": {
    "methods": [
      "password"
    ],
    "roles": [
      {
        "id": "<MEMBER_ID>",
        "name": "_member_"
      },
      {
        "id": "<ADMIN_ID>",
        "name": "admin"
      }
    ],
    "expires_at": "2017-04-26T16:04:17.141683Z",
   }
}

Note
For more information on curl, see the curl:// site.

Using PowerShell

If you use PowerShell, you may encounter different behavior because the curl command could be an alias to a PowerShell cmdlet. Try using the curl.exe command in place of curl.

To check how the curl command in PowerShell resolves:

c:\> Get-Command curl

CommandType   Name
-----------   ----
Alias         curl -> Invoke-WebRequest