Use cURL

cURL is an open source, command-line tool for transferring data with URL syntax, supporting various protocols including HTTP and HTTPS. The examples in this document use cURL to demonstrate how to access the Compute Classic REST API.

For information about downloading and installing cURL, see Quick Start. You must install a version of cURL that supports SSL.

For more information about authentication requirements, see Authentication.

Once installed, to use cURL to access the Compute Classic REST API:

  • Set the CURL_CA_BUNDLE environment variable to the location of an SSL certificate authority (CA) certificate file or bundle to authenticate against the Verisign CA certificate. Alternatively, you can specify the location of your local CA certificate bundle on the command line by using the --cacert option.

    You can download an SSL CA certificate bundle from http://curl.haxx.se/docs/caextract.html or provide your own. For information about CA certificate verification using cURL, see  http://curl.haxx.se/docs/sslcerts.html.

  • Invoke cURL and specify one or more of the command-line options defined in the following table, as required, to direct its execution.

    cURL Option Description
    --cacert Specifies the location of the CA certificate bundle on the local machine.

    Note:

    It is not mandatory to provide this option while running cURL commands. However, if the Peer certificate cannot be authenticated with known CA certificates error occurs, use this option to provide the location of the appropriate certificate file or bundle.

    -d, --data @file.json Identifies the request document, in JSON format, on the local machine.
    -F, --form @file.json Identifies form data, in JSON format, on the local machine.
    -H Defines one or both of the following:
    • Content type of the request document

    • Accept header

    -i Displays response header information.
    -u, --user username:password Specifies the user name and password for the Compute Classic account. You don't have to pass the user name and password with every request if you are passing an authentication cookie. For more information, see Authentication.
    -X Indicates the type of request, such as GET, POST, DELETE, or PUT.

For example:

curl -i -X GET 
        --cacert ~/cacert.pem
        -u <username>:<password> 
        -H <request-header>:<value> 
        https://<api-endpoint>/<path>/<resource-path>

The following example cURL command creates a storage volume named myVolume in the /Compute-acme/jack.jones@example.com service instance:

curl -X POST 
     -H "Cookie: $COMPUTE_COOKIE" 
     -H "Content-Type: application/oracle-compute-v3+json" 
     -d '{"size": "10G", 
          "properties": ["/oracle/public/storage/default"], 
          "name": "/Compute-acme/jack.jones@example.com/myVolume"}' 
     https://api-z999.compute.us0.oraclecloud.com/storage/volume/

COMPUTE_COOKIE is the name of the variable in which you store the authentication cookie. For more information, see Authentication.

Note:

For information about the URLs to which you should send HTTP requests, see Send Requests.