Oracle Cloud Infrastructure offers many useful services that your organization and apps could use, and in some cases you might want to leverage them from an Oracle Visual Builder app. An easy way to do that is to use the REST APIs these services provide.

This post will walk you through the steps to create a Service Connection for the OCI REST API in your Visual Builder application.  You will be able to access your OCI account directly from your new application and perform any of the available API commands.  For example, you could:

  • Create an application that allows your users to start and stop compute instances in specific compartments, without having to give them access to your cloud console.
  • Integrate OCI Notifications into your application to send alerts and messages to Oracle Functions, email, SMS, and message delivery partners, including Slack, PagerDuty, and ServiceNow.

There are many things you can do, this post will get you started.

Prerequisites

  • Oracle cloud account.
  • Cloud user with permissions to use the REST API.

User API key

In order to access the REST API you will need an API key.

To upload or create a new key:

  1. Log into your cloud account and open your User Settings.
    Open User Settings

     
  2. Under Resources, click on "API Keys".
    Resources API Keys

     
  3. If you do not already have an API Key setup that you would like to use, click the "Add API Key" button.
    Add API Key

    If you have an API Key Pair that is not setup on this cloud account, select "Choose Public Key File" to upload it or select "Paste Public Key" to copy and paste it.
    Important: You are only adding the public key here.  Do not upload or paste your private key.

    If you need a new key, select "Generate API Key Pair" and download the Private Key.  The public key for this new pair will be saved in your API Keys.  You can also download the public key if you'd like, but you won't need it for this example.
    Save the Private Key in a secure location, this key can be used to access your account.
     
  4. Open the menu to the right of your key and click "View Configuration File".
    View Config File

     
  5. Copy the API Key Fingerprint and Configuration File Preview information, you'll need this later.
    Configuration File Preview

     
  6. For this example I will be using the Compute Instances API which requires a Compartment OCID.
    In the cloud console menu, open Identity & Security / Compartments.
    Open Compartments

     
  7. Locate the compartment that contains the instances you want to work with and copy it's OCID.
    Copy Compartment OCID

    Save this and the above information, you will need it later to connect to the API.

Visual Builder

Open Visual builder and create a new application.

Create a Service Connection

This section will show you how to create a Service Connection to the Core Services API / Instance / ListInstances endpoint.  The authentication steps will be the same for other endpoints, but you may need to customize the REST calls.

  1. Create a new Service Connection.
    New Service Connection

     
  2. Select Define by Endpoint.
    Define by Endpoint

     
  3. Enter the URL for the API you want to use.  In this example I'm using Core Services API / Instance / ListInstances.  The URL for the Ashburn region is "https://iaas.us-ashburn-1.oraclecloud.com/20160918/instances".
     
  4. Set the method to GET.
     
  5. Set the Action Hint to "Get Many".
     
  6. Click Next.
    Enter URL

     
  7. Enter a Service Name and Title.
    Overview Tab

     
  8. Change to the "Server" Tab.
  9. Under Authentication choose "Oracle Cloud Infrastructure API Signature 1.0"
    Server Tab

     
  10. Click the pencil icon to edit the Key Id.  This is where you'll need the information you copied in the first step.
    Edit Key ID

     
  11. Enter your Key Id.  This will be your "TenancyOCID/UserOCID/KeyFingerprint" found in the information you saved before.
    The 3 pieces of data are separated with a "/".  There should be no spaces in this string.
  12. Enter the private key that you saved.
  13. Click Save.
    API Signature

    The remaining steps in this post cover how to setup the specific "List Instances" API endpoint.  Other endpoints may have different steps.
     
  14. Switch to the Operation tab.
  15. Enter an Endpoint ID.
    Operation Tab

     
  16. Switch to the Request tab.
  17. Click "Add Dynamic Query Parameter"
  18. Set the Name to "compartmentId" and mark it as Required.
    Request Tab

     
  19. Switch to the Test Tab.
  20. Under the Query Parameters tab enter the Compartment OCID from above in the Value for compartmentId.
  21. Click "Send Request".
    Send Test Request

     
  22. You should get a response similar to this.
  23. Click "Save as Example Response.
    Save Response

     
  24. Click "Create".

Quick Test Application

Now that you have a working Service Connection, you can use it in your Visual Builder application the same way you would use any other Service Connection.

The following steps will show you how to make a simple "proof of concept" application for the List Instances Service Connection.

  1. Create a new Visual Builder Application.
  2. Enter an Application Name.
  3. Click Finish.
    Create Visual Builder Application

     
  4. In the left menu, select the Web Apps icon.
  5. Click the new "Web Application" button.
    New Web App

     
  6. Enter an Application Name.
  7. Click Create.
    Enter Application Name

     
  8. Under the Data Tab, expand Services/OCI-Instances/Other Endpoints.
  9. Drag "Get Many" service and drop it in the new web app.
    Drop Data Object

     
  10. In the "Render as" menu, choose "Table".
    Render as Table
  11. Under the Endpoint Structure select
    1. displayName
    2. shape
    3. lifecycleState
  12. Click Next.
    Select Fields

     
  13. Under Target, click on compartmentId*.
    Normally, you would create a page variable set as the value of a component that you could use to choose the compartment.  This is only a proof of concept so we'll take the easy road and set it as a static value.
  14. Select Static Content.
  15. Enter the Compartment OCID from above.
    Set Compartment OCID

     
  16. Click Finish.
  17. Make sure you're in "Design" mode.
  18. Select the table and expand it to 12 columns.
    Expand the Table

You should see the displayName, shape and lifecycleState of the compute instances that are in the chosen Compartment.

Jump back over to your OCI Console and start or stop one of the instances, then refresh your app to see that the status is being displayed correctly.

If you'd like to have a little extra fun, you could add buttons on each row to start and stop the compute instance from your new Visual Builder application.

Hint:  Add a POST endpoint to the instances Service Connection using an Instance Action.