OCI Usage REST API EXAMPLE


A recipe for getting consumption ir usage with the OCI usage rest API.

First, clone this repo

git clone https://github.com/javiermugueta/oci-rest.git
cd oci-rest

Set your environment

put your pivate key in a file called myppk
vi my-oci-env
...
#
# put here your tenancy and user data
#
 tenancyId="ocid1.tenancy.oc1..aaaaaaaaei...";
 authUserId="ocid1.user.oc1..aaaaaa...";
 keyFingerprint="eb:...";
#
 privateKeyPath=./myppk
#

Put in a json file the request, for exmaple:

{
 "granularity": "HOURLY",
 "tenantId": "ocid1.tenancy.oc1..aaaaaaaaeicd...",
 "timeUsageStarted": "2021-02-10T00:00:00.000Z",
 "timeUsageEnded": "2021-02-11T00:00:00.000Z"
 }

Now run this using the endpoint according with your primary (home) region

./oci-rest usageapi.eu-frankfurt-1.oci.oraclecloud.com post body.json "/20200107/usage" 
 
 Usage:
       oci-rest <api-endpoint-without-protocol> <verb> [<jsonfile for post verb>] <method>
 verb: get, post,...
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 {
   "groupBy" : null,
   "items" : [ {
     "tenantId" : null,
     "tenantName" : null,
     "compartmentId" : null,
     "compartmentPath" : null,
     "compartmentName" : null,
     "service" : null,
     "resourceName" : null,
     "resourceId" : null,
     "region" : null,
     "ad" : null,
     "weight" : null,
     "shape" : null,
     "skuPartNumber" : null,
     "skuName" : null,
     "unit" : null,
     "discount" : null,
     "listRate" : null,
     "platform" : null,
     "timeUsageStarted" : "2021-02-10T12:00:00.000Z",
     "timeUsageEnded" : "2021-02-10T13:00:00.000Z",
     "computedAmount" : null,
     "computedQuantity" : 0,
     "overagesFlag" : null,
     "unitPrice" : null,
     "currency" : " ",
     "subscriptionId" : null,
     "overage" : null,
     "tags" : [ {
       "namespace" : null,
       "key" : null,
       "value" : null
     } ]
   }, {
     "tenantId" : null,
     "tenantName" : null,
....

That’s all, hope it helps! 🙂

See also

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.