IBM Cloudability

IBM Cloudability

 View Only
Expand all | Collapse all

(APIs) Getting Started with Cloudability APIs

  • 1.  (APIs) Getting Started with Cloudability APIs

    Posted Wed January 13, 2021 09:49 PM
    Automation.  We've all heard the term, and in organizations around the world, teams are working on building automation that can allow us to focus on the more pressing, random tasks that come to us throughout the day.

    APIs are the key to automation.  Cloudability's APIs are publicly available to any Cloudability User or Administrator, and you can take advantage of them TODAY!

    To begin, you'll want to determine the tool that you're going to use for the APIs.  You can use the terminal built into MacOS, Linux, or Windows, you can use a programming language like Python or Powershell if that's more familiar to you, or you can use a standalone tool such as PostMan.  As a TAM, I often recommend that my clients start with PostMan to test their APIs or even just as a quick way to run a one-off API when needed (I'm looking at YOU Business Mappings!).  If you need help with PostMan, please refer to this knowledge documentation.

    Once you have selected your tool (I'm going to focus on PostMan for the rest of this post), you'll need to gather your API Key.  Cloudability allows any user or administrator to get their own unique API Key (at no additional charge) from User Preferences (link to user preferences in CLDY).  On the right side of the preferences page, you will either see an API Key and an option to rotate the key (if you've requested one already) or you'll see the option to enable a new API Key.
    NOTE: You should keep your API Key in a secure location such as OneKey or another trusted password manager.  If you accidentally share your API Key in a script, email, or otherwise, it is recommended that you rotate your API Key as soon as possible!

    Now that you have your API Key, you can use it in PostMan.  Here are the steps you would need to take to use that API Key to perform a task such as requesting your Azure Rightsizing recommendations from Cloudability!
    1. Navigate to the authorization tab in PostMan, choose "Basic Auth" from the drop menu, and put in your API Key as the Username.  You don't need to enter a password.
    2. Gather the URL of the API from the Cloudability API Documentation
    3. Make sure that the REST method (to the left of where you enter the URL) is set to GET for this request.
    4. Click the Send button
    5. Review your results!

    Whoa!  Do those results look odd?  It's not a CSV, it's JSON!  Cloudability, like most API-driven applications use JSON to pass data back & forth.  The reason for this is that JSON allows for multiple layers of results while CSV only allows for columns & rows.  To learn more about JSON, you can learn more here at no additional charge!

    Depending on the type of API that you're wanting to run, you may need to modify some things.  Some APIs use different REST methods such as PUT, POST, or even DELETE.  Those types of APIs often require information in the "body" tab of PostMan.  That's a discussion for a different post where we can dive deeper into APIs.

    What are some API use cases that you're using in your organization?

    ------------------------------
    Phillip Purcell
    Technical Account Manager
    Apptio Cloudability
    ------------------------------

    #Cloudability


  • 2.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Thu January 14, 2021 02:05 AM
    Thanks for sharing @Phillip Purcell :-) Something of interest @Oliver Smith?​​


  • 3.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Mon July 12, 2021 05:21 PM
    Hi @Phillip Purcell - really like automating with the Cldy API; already using for things like business mappings updates, user info, etc. 

    Are there more advanced examples or docs for things like downloading a cost report, (building and retrieving csv via api). For instance, a call to pull data for Cost (Total), last 30 days, by AWS tag value? (without actually creating the report). 

    Thanks,

    Jeff​


  • 4.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Mon July 12, 2021 06:03 PM
    Great question - And yes, we could certainly produce many examples of API calls being used for reports.  However, due to the custom nature of Tags, Business Mappings, Account Groups, etc. for each company, I generally recommend starting with the question of what you're wanting to do with the data first.  Some people want to take the data out to be put into another source, such as PowerBI, while others may want to use the data as part of a larger workflow or integration.  As an example of that, while we have the integration with Jira Cloud today that enables a Rightsizing workflow, those that use ServiceNow or other ITSM tooling may want to create their own workflows for informing engineers so they may take actions on their instances.

    Once you know the data that you're wanting to see (and why you want to see it), the question of which Dimensions and Metrics to include (as well as filters) will start to come into focus.  From there, you can begin to build the report you're looking for.  The hardest part, in my own experience, is remembering to use the name of the dimension/metric associated with the API instead of exactly what you'd see in the UI.  For example, "Cost(Total)" in the UI is named "unblended_cost" in the API.  Likewise, the tags your organization has mapped may be called "Line of Business" or "Cost Center" in the UI, but in the API it may appear as "tag4".

    The best & easiest way to identify the name in the API is to run the below API call.  It'll return the label (UI name) and name (API name) that we use.  You'll find that many of these are different, and that could be for any number of reasons.  Sometimes it's that we built the backend first then gave it a "friendlier" name in the UI later.  Sometimes it's because we have to have a standardized schema for our own backend structures, which wouldn't look nearly as nice as allowing our users to name their own Tag Mappings and Business Mappings.

    curl --location --request GET 'https://app.cloudability.com/api/1/reporting/cost/measures' \
    --header 'Authorization: Basic {{INSERT_YOUR_ENCODED_API_KEY_HERE}}' \

    And here's an example of the Cost(Total) metric as you would see it in the response of the above API call.

    {
       "label": "Cost (Total)",
       "name": "unblended_cost",
       "description": "Total cost calculated by the unblended rate.",
       "data_type": "currency",
       "type": "metric",
       "group": {
          "cube_type": "cost",
          "id": 2,
          "key": "billing",
          "name": "Billing"
       },
          "sub_group": {
          "cube_type": "cost",
          "id": 3,
          "key": "costs",
          "name": "Costs"
       }
    }

    Hopefully this will be helpful as you begin to explore the possibilities in the world of the Cloudability API!

    ------------------------------
    Phillip Purcell
    Technical Account Manager
    Apptio Apptio
    ------------------------------



  • 5.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Tue July 13, 2021 09:29 AM
    Thanks @Phillip Purcell - good stuff. I'll tinker with your suggestions and report back. Cheers.​


  • 6.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Wed July 21, 2021 03:54 PM
    @Phillip Purcell - your example call above works fine to determine parameter syntax, thanks. However, I'm still having trouble getting useful returns from calls to the reporting api. I'm using the developer console on the Cldy website to get ideas, and testing in terminal and Postman. Do you have an example of a call for a simple cost report? If so, I can build out the rest. Something like Cost (Total) for any date range, just one dimension like Vendor Product Name. e.g. output (json or whatever):



    The outcome of a cost reporting call would be parsed and used to build custom datasets for automating emails, slack notifications or other processes. ​​


  • 7.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Wed July 21, 2021 04:12 PM
    Hey Jeff - Glad to hear that the above call is working for you.  I'll try to get a bit more specific, but please understand that the nomenclature for things such as your tag mappings or business mappings would be different from that of other customers, so I'm going to stick to the default Dimensions & Metrics available "out of the box".

    Here's an example of a report that pulls the aggregate spend totals for every account over the last 30 days : 
    curl --location --request GET 'https://app.cloudability.com/api/1/reporting/cost/run?dimensions=vendor_account_name&metrics=unblended_cost&start_date=30+days+ago+at+00%3A00%3A00&end_date=23%3A59%3A59&order=desc&sort_by=vendor_account_name' \
    --header 'Authorization: Basic {{INSERT_YOUR_ENCODED_API_KEY_HERE}} \

    And this is an example of a report that pulls the aggregate spend totals for every day over the last 90 days : 
    curl --location --request GET 'https://app.cloudability.com/api/1/reporting/cost/run?dimensions=date&metrics=unblended_cost&start_date=90+days+ago+at+00%3A00%3A00&end_date=23%3A59%3A59&order=desc&sort_by=date' \
    --header 'Authorization: Basic {{INSERT_YOUR_ENCODED_API_KEY_HERE}}' \

    If you'd like additional examples, I'm happy to supply them, though because I am not the TAM assigned to your account, I do not have access to your company's Cloudability instance.  Depending on the type of call you're needing to configure, I would also recommend reaching out to your Cloudability TAM for assistance.  I think the above calls SHOULD get you where you need to be, though.

    I will also add that, while it's less performant and more likely to time out the back end API, you can often change '/run?' to '/run.csv?' to receive the response in CSV format instead of JSON.  This is an exclusive feature of Cost Reports, and it's not officially documented as it's a very niche feature that does not work in all other APIs.

    Hopefully that's helpful!  Let me know if I hit the mark or if you're still looking for something a little different.

    ------------------------------
    Phillip Purcell
    Technical Account Manager
    Apptio Apptio
    ------------------------------



  • 8.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Wed July 21, 2021 04:18 PM
    Edited by Jeff Hyatt Tue November 05, 2024 06:04 PM
    @Phillip Purcell - this is great and I think just what I was looking for - they work! I was missing the "/run" section on the URL.  would help if I could read better :-p

    I have no problem determining syntax or ids for our custom fields via the console or the "measures" call you provided.

    Thanks!​


  • 9.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Wed July 21, 2021 04:21 PM
    Huzzah!!  Glad to hear it!

    Another fun note : if the report you're running is a "larger" report (such as pulling several months or a large qty of rows returned), you may consider using the enqueue option.  The enqueue option is detailed in our API Documentation, but in short it starts the request and generates the report in the background.  The system will only initially return to you an indexID for the report, which you can use to check the status of the report and, when completed, gather the results

    ------------------------------
    Phillip Purcell
    Technical Account Manager
    Apptio Apptio
    ------------------------------



  • 10.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Wed July 21, 2021 04:23 PM
    Very cool - thanks for the tips!


  • 11.  RE: (APIs) Getting Started with Cloudability APIs

    Posted Sun August 08, 2021 05:40 AM
    Thanks for the sharing. I see v3 api doc mentioned the filter query parameter,  does v2 api supports filter also? 

    FYI, I tried filter query parameter in following request by v2 api, but not work.  If filter only work on v3 api,  is there is v3 api to get utilization report?

    https://app.cloudability.com/api/2/reporting/compare/enqueue?order=desc&metrics[]=inbound_bandwidth&metrics[]=outbound_bandwidth&metrics[]=total_bandwidth&sort_by=inbound_bandwidth&dimensions[]=vendor_account_identifier&dimensions[]=vendor_account_name&dimensions[]=group_name2&dimensions[]=region&dimensions[]=vpc_id&dimensions[]=subnet&start_date=2021-06-16&end_date=2021-07-16&filter=vpc_id==vpc-8eb6cbf6