IBM Cloudability

IBM Cloudability

 View Only
Expand all | Collapse all

How to create a views by using APIs

  • 1.  How to create a views by using APIs

    Posted Tue August 22, 2023 01:05 PM

    Hello there,

    I hope you're doing good!

    My question is how I can create a views in Cloudability by using APIs (Postman)

    So, I think this is possible but the question here is: How I can do that?

    If you have any video to show me, will help me a lot

    Thanks


    #Cloudability


  • 2.  RE: How to create a views by using APIs

    Posted Wed August 23, 2023 01:23 PM

    the API documentation on this is pretty good -  recommend following it: https://help.apptio.com/en-us/cloudability/api/v3/views_end_point.htm. 

    I'm able to create views with the following (replace ### with your Cldy API key):

    curl -X POST https://api.cloudability.com/v3/views \
         -H 'Content-Type: application/json' \
         -u '###:' \ 
         -d @- << EOF
    {
      "title": "My New view",
      "sharedWithOrganization": true,
      "sharedWithUsers": [
            "12345",
            "34567"
            ],
      "filters": [
        {"field":"tag3","comparator":"==","value":"app1"},
        {"field":"tag3","comparator":"==","value":"app2"},
        {"field":"tag3","comparator":"==","value":"app3"},    
      ]
    }
    EOF

    You could parse that out and use Postman. 




  • 3.  RE: How to create a views by using APIs

    Posted Wed August 23, 2023 02:34 PM

    Hey Jeff,

    Thanks for your responding.

    When I click in "Send" appears the error 401

    {
        "error": {
            "status": 401,
            "code": "unauthorized",
            "messages": [
                "missing auth tokens"
            ],
    And, another question...
         -H 'Content-Type: application/json' \
         -u '###:' \ 
         -d @- << EOF
    This informations, where I use that? (I'm newbie in APIs, sorry for the dumb question)
    Thanks in advance



  • 4.  RE: How to create a views by using APIs

    Posted Wed August 23, 2023 04:23 PM

    the 401 (unauthorized) means you haven't provided your API key or something related. 

    I'd start with simple GET calls first. If using Postman, are you able to create a new HTTP request by placing this:

    https://api.cloudability.com/v3/views

    in the URL part and your Cloudability API Key in the Authorization tab (choose basic auth). Paste your API key into the Username field and leave the Password blank. Click send and see if you get back a list of Views. 




  • 5.  RE: How to create a views by using APIs

    Posted Wed August 23, 2023 06:41 PM

    Here's another simple one I tested you can try (this is formatted for Terminal on a Mac, not Postman). 

    curl -X POST https://api.cloudability.com/v3/views \
         -H 'Content-Type: application/json' \
         -u 'YOURAPIKEY:' \
         -d @- << EOF
    {
      "title": "Farmer Team View",
      "sharedWithOrganization": true,
      "sharedWithUsers": [],
      "filters": [{"field":"tag5","comparator":"==","value":"farming"}]
    }
    EOF

    remember to replace "YOURAPIKEY" with your Cldy API Key. 




  • 6.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 10:52 AM

    Hey Jeff,

    I replace my API Key and I get back a list of Views. This works :)

     But when I tried to use your another sample to create a view appears a error message:

    {
        "error": {
            "status": 400,
            "code": "request_validation_failed",
            "messages": [
                "Bad Request"
            ],
            "uniqueid": "35937cea-428a-11ee-b315-b6cbfc08ba6f",
            "typeid": "2852c3883e50336ebff16a374642f8f0",
            "traceid": "3590aa79-428a-11ee-b315-b6cbfc08ba6f",
            "service": "Sancho"
        }
    }

    What's happen here? Can you help me?




  • 7.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 10:59 AM

    Futhermore,

    I don't know  if I made something wrong in my code, but if possible for you analyze you'll find the image below about that:




  • 8.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 11:18 AM

    Sorry - I'm not a postman expert - but likely could be some headers that it adds that are causing problems. Can you use cURL on the command line? 

    i've tested this example with success multiple times. (replace [auth_token] with your key).

    curl -X POST https://api.cloudability.com/v3/views \
         -H 'Content-Type: application/json' \
         -u '[auth_token]:'  \
         -d @- << EOF
    {
      "title": "Farmer Team View",
      "sharedWithOrganization": true,
      "sharedWithUsers": [],
      "filters": [{"field":"tag5","comparator":"==","value":"farming"}]
    }
    EOF

    --
    Jeff




  • 9.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 01:20 PM

    Can you share a print Screen of your display with the structure of your code and headers?




  • 10.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 02:05 PM

    It's exactly as it appears in my last reply. Did you try using the cURL command (instead of Postman)? 

    If you are still having issues, you may want to open a ticket with Cloudability support. 




  • 11.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 02:16 PM

    Yes, I'm tried to use the cURL command in Postman

    How can I open the ticket with Cloudability Support? Do you have a link?




  • 12.  RE: How to create a views by using APIs

    Posted Thu August 24, 2023 02:27 PM

    I've never used cURL in Postman - it's meant for the command line in Windows or Terminal on a Mac. 

    Support is available via the help menu in Cloudability: 

    Also - here's a good blog post that might help with both cURL and Postman usage: https://blog.hubspot.com/website/curl-command.




  • 13.  RE: How to create a views by using APIs

    Posted Sat August 26, 2023 01:00 PM

    Meanwhile,

    That you showed:

         -H 'Content-Type: application/json' \
         -u '[auth_token]:'  \
         -d @- << EOF

    Where I add this? And what means all informations?

    I'm really confused with that. I don't know what means "-H", "-u" and "-d @-"

    Furthermore,

    That's now appears for me meanwhile I try again:

    {
        "error": {
            "status": 400,
            "code": "request_validation_failed",
            "messages": [
                "Bad Request"
            ],
            "uniqueid": "f59539c1-4430-11ee-b54d-42aa02367cbe",
            "typeid": "2852c3883e50336ebff16a374642f8f0",
            "traceid": "f5929005-4430-11ee-b54d-42aa02367cbe",
            "service": "Sancho"
        }
    }



  • 14.  RE: How to create a views by using APIs

    Posted Thu September 07, 2023 03:14 PM

    Hi, I''m not sure if this is still a problem but for the field name it has to be in a specific format. You can get a list of the available measures using the following api call (from the API docs)

    curl 'https://api.cloudability.com/v3/reporting/cost/measures' -u '[auth_token]:'

    In your example you have "field":"Resource Group Test" but the example provided used "field":"tag5". The API call I provided will allow you to map your "Resource Group Test" dimension to the appropriate field name used when creating views.