cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bill Analysis API Question

Hello,

I am currently attempting to utilize the costs api as detailed here: https://reference.rightscale.com/bill_analysis/?url=swagger_adj.json#/ specifically the "select costs" endpoint. When I make an authenticated request ( via OAuth token ) to this endpoint I receive a: 

301 Moved Permanently; Location: https://us-4.rightscale.com

followed by a: 

302 Found; Location: https://us-4.rightscale.com/acct/<acct_id>/dashboard;overview

and then a loop of 302's bouncing between https://us-4.rightscale.com & https://us-4.rightscale.com/acct/<acct_id>/dashboard;overview 

Here's an example curl request that I'm using: 

curl --include -L \
        -H "X-API-Version:1.0" \
        -H "Authorization: Bearer <oauth access token>"  \
        -H "Content-Type: application/json" \
        --request POST \
        --data "$PAYLOAD" https://us-4.rightscale.com/orgs/<org_id>/costs/select

Here's the payload that I'm including: 

{
  "billing_center_ids": [
    "<billing_center_id>"
  ],
  "dimensions": [
    "vendor",
    "category",
    "service",
    "instance_type",
    "billing_center_id",
    "usage_unit"
  ],
  "end_at": "2020-02",
  "filter": {
    "dimension": "vendor",
    "type": "equal",
    "value": "aws"
  },
  "granularity": "month",
  "limit": 1000,
  "metrics": [
    "usage_amount"
  ],
  "start_at": "2020-01"
}

Any help you might be able to provide would be greatly appreciated.

Thanks!

 

Ryan

(2) Solutions

Hi.

 

Thats great. Authentication works and querying the API also does not return an error.

Could you try targeting a billing center you've created ? In the example below the target BC is unallocated (catch-all) .  Also for the dimensions try including just vendor_account , to test a simpler query.  Based on the response it was unable to find any data in that BC.  

 

      -X POST "https://optima.rightscale.com/bill-analysis/orgs/<org_id>/costs/select" -d '{"billing_center_ids":["unallocated"],"dimensions":["vendor_account","service","resource_id"],"metrics":["cost_amortized_blended_adj"],"end_at": "2020-03","limit": 1000,"start_at": "2020-02"}' 

 

Hope that helps

View solution in original post

(9) Replies

Hello,

Thanks! That certainly fixed the 302/301 redirect loop. Now I'm getting an error msg that says it doesn't accept "POST" requests. Do you happen to have updated docs for this endpoint? 

 

Thanks,

 

Ryan

API_ENDPOINT='us-4'


my_token_endpoint="https://$API_ENDPOINT.rightscale.com/api/oauth2"
my_refresh_token="get-this-from-the-platform"

#generate $access_token
curl --include \
   -H "X-API-Version:1.5" \
    --request POST "$my_token_endpoint" \
    -d "grant_type=refresh_token" \
    -d "refresh_token=$my_refresh_token"


curl --include \
      -H "API-Version:1.0" \
      -H "Authorization: Bearer $access_token" \
      -H "Content-Type: application/json" \
      -X POST "https://optima.rightscale.com/bill-analysis/orgs/<org_id>/costs/select" -d '{"billing_center_ids":["unallocated"],"dimensions":["vendor_account","service","resource_id"],"metrics":["cost_amortized_blended_adj"],"end_at": "2020-03","limit": 1000,"start_at": "2020-02"}' 

The end point accept POST.  Can you post the full error msg you are receiving and your code ? https://reference.rightscale.com/bill_analysis/?url=swagger_adj.json#/costs/costs_select

 

Thanks 

Hi,

Here's the error message: "{"id":"81FuN0rz","code":"method_not_allowed","status":405,"detail":"Method POST must be one of GET, HEAD, OPTIONS","meta":{"allowed":"GET, HEAD, OPTIONS","method":"POST"}}"

And the code is literally just the curl command I've posted previously, here's the full curl command I'm using minus the authentication token and billing center id: 

curl --include -L -H "X-API-Version:1.0" -H "Authorization: Bearer <authentication_token>" -H "Content-Type: application/json" --request POST --data "{ "billing_center_ids": [ "<billing_center_id>" ], "dimensions": [ "vendor", "category", "service", "instance_type", "billing_center_id", "usage_unit" ], "end_at": "2020-02", "filter": { "dimension": "vendor", "type": "equal", "value": "aws" }, "granularity": "month", "limit": 1000, "metrics": [ "usage_amount" ], "start_at": "2020-01" }" "https://optima.rightscale.com/orgs/27378/costs/select"

Hello,

Ok, so after going over the script again I've updated the URL to: https://optima.rightscale.com/bill-analysis/orgs/<org_id>/costs/select. Updated the Authorization Header to 'Api-Version: 1.0' and wrapped all of the headers / post data in single quotes as opposed to double quotes and I do not have any errors now. 

Unfortunately I am not receiving any data back from the endpoint either, the endpoint returns the following: `{"rows":[]}`. I also tried increasing the date range to 2020-01 -> 2020-03 but that didn't help either. 

Thanks again for all your help so far!

 

Ryan

Hi.

 

Thats great. Authentication works and querying the API also does not return an error.

Could you try targeting a billing center you've created ? In the example below the target BC is unallocated (catch-all) .  Also for the dimensions try including just vendor_account , to test a simpler query.  Based on the response it was unable to find any data in that BC.  

 

      -X POST "https://optima.rightscale.com/bill-analysis/orgs/<org_id>/costs/select" -d '{"billing_center_ids":["unallocated"],"dimensions":["vendor_account","service","resource_id"],"metrics":["cost_amortized_blended_adj"],"end_at": "2020-03","limit": 1000,"start_at": "2020-02"}' 

 

Hope that helps

Hi,

So that seems to have done it. I am now retrieving information when I make an API call. Now I just need to figure out how to retrieve the data that I'm looking for. You wouldn't happen to know which dimensions I'll need to include to retrieve instance ( AWS EC2 Id's ) level information would you? 

Thanks again!

 

Ryan 

Thanks again for all your help!