Configuration & Test of OCI Credentials in APEX
If you want to use the OCI APIs in APEX, you'll need to create OCI Credentials. Here is a step-by-step guide.
These instructions also correctly place the files in an .oci folder for future use by apps such as CLI Tools
Setup OCI key
Window Key + R% and type %USERPROFILE%
If you are in unix, you want to navigate to your home folder
Create an .oci folder
In OCI, Click Profile > My Profile
Click API Keys > Add API Key > Download API Key
Don't touch anything in OCI yet
Copy this downloaded file to %USERPROFILE%\.oci (or Home folder in Unix)
Back in OCI click Add
Don't touch anything in OCI yet, keep the window open
Save the contents of the above to a new file called %USERPROFILE%\.oci\config (or Home folder in Unix) Note: the file does not have a file extension
Change the last line to (change as necessary)
key_file=c:\full\path\to\folder\.oci\oci_api_key.pem
My folder looks like this
Web Credentials
In APEX, click Workspace Utilities > Web Credentials >Create
Set the first 3 boxes like this
Paste the contents of the PEM file you downloaded into the OCI Private Key
Paste the values from the config file for OCI User ID, OCI Tenancy ID & OCI Public Key Fingerprint
Click Create
Testing
Create / Edit an APEX applicaton
Create a Dynamic Content Region called Result from OCI
Paste the following, changing the l_region_name if appropriate.
DECLARE l_region_name CONSTANT VARCHAR2(32767) DEFAULT 'eu-frankfurt-1'; l_credential_static_id CONSTANT VARCHAR2(32767) DEFAULT 'oci'; l_response CLOB; BEGIN -- Make the REST request l_response := APEX_WEB_SERVICE.make_rest_request( p_url => apex_string.format( 'https://identity.%0.oraclecloud.com/20160918/regions', l_region_name ), p_http_method => 'GET', p_wallet_path => NULL, -- Use this if you're using a wallet p_wallet_pwd => NULL, -- Use this if you're using a wallet p_credential_static_id => l_credential_static_id ); RETURN l_response; END;
Run the page
Results
If your OCI credentials worked, you'll see this.
If your OCI credentials do not work, you'll see this.
Enjoy!
What's the picture? A brief stop whilst Mountain Biking right here.
Subscribe to my newsletter
Read articles from Matt Mulvaney directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Matt Mulvaney
Matt Mulvaney
With around 20 years on the job, Matt is one of the most experienced software developers at Pretius. He likes meeting new people, traveling to conferences, and working on different projects. He’s also a big sports fan (regularly watches Leeds United, Formula 1, and boxing), and not just as a spectator – he often starts his days on a mountain bike, to tune his mind.