2.13 Calling Oracle Cloud Infrastructure REST APIs Using the OCI Command

Starting from SQLcl release 20.2, you can call Oracle Cloud Infrastructure (OCI) REST APIs using the OCI command.

Prerequisites

To use the OCI command, you need to first set the OCI profile for authentication and access.

For more information about how to set up the required SSH keys and configure your Oracle Cloud Infrastructure Software Development Kits, see Setup and Prerequisites in the Oracle Cloud Infrastructure Documentation.

To list profiles contained in the OCI configuration file at ~/.oci/config, enter:

oci profile

To set the profile name as "demo", enter:

oci profile demo

From SQLcl release 23.3, if you have a DEFAULT OCI profile installed, it is loaded when starting SQLcl.

Two Syntax Formats

There are two syntax formats available for using the OCI command.

Specify Target

In the first syntax format, the target is specified completely in the OCI command:

oci <host> <method> [file-to-send-as-body] <request-target> 

where

method is GET, PUT or DELETE.

request-target is the path to the namespace, bucket or object on host.

Examples

To delete the emp.csv file from testing-bucket:

oci objectstorage.us-ashburn-1.oraclecloud.com delete /n/abc123/b/testing-bucket/o/emp.csv 

To list the contents of testing-bucket:

oci objectstorage.us-ashburn-1.oraclecloud.com get /n/abc123/b/testing-bucket/o/ 

To put the emp.csv file into testing-bucket:

oci objectstorage.us-ashburn-1.oraclecloud.com put ./emp.csv /n/abc123/b/testing-bucket/o/emp.csv

To get the emp.csv file from testing-bucket:

oci objectstorage.us-ashburn-1.oraclecloud.com get /n/abc123/b/testing-bucket/o/emp.csv 

Specify Target using Cloud Storage Command

In the second syntax format, the target is a complete or partial URL to the location, which is set using the Cloud Storage command (cs):
oci <method> [file-to-send-as-body] <qualifier>

where

method is GET, PUT or DELETE.

qualifier is the cloud storage namespace or bucket. qualifier is appended to the location specified on the set Cloud Storage command and must form the complete URL to the namespace, bucket, or object used by the method.

For more information about the Cloud Storage command, see Using Cloud Storage.

Examples

To delete emp.csv from testing-bucket:

cs objectstorage.us-ashburn-1.oraclecloud.com
oci delete /n/abc123/b/testing-bucket/o/emp.csv 

To list contents of testing-bucket:

--Using the OCI Command (oci get)

cs objectstorage.us-ashburn-1.oraclecloud.com/n/abc123/b/testing-bucket/o/
oci get

--Using the Cloud Storage Command (cs listo)

cs objectstorage.us-ashburn-1.oraclecloud.com/n/abc123/b/testing-bucket/o/
cs listo

To put emp.csv into testing-bucket:

cs objectstorage.us-ashburn-1.oraclecloud.com/n/abc123/b/testing-bucket
oci put ./emp.csv /o/emp.csv 

To get emp.csv from testing-bucket:

cs objectstorage.us-ashburn-1.oraclecloud.com/n/abc123/b/testing-bucket
oci get /o/emp.csv