Skip to main content
POST
/
billing_rules
Create billing rule
curl --request POST \
  --url https://api.vantage.sh/v2/billing_rules \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "title": "<string>",
  "start_period": "<string>",
  "start_date": "<string>",
  "end_date": "<string>",
  "apply_to_all": true,
  "charge_type": "<string>",
  "percentage": 123,
  "service": "<string>",
  "category": "<string>",
  "sub_category": "<string>",
  "amount": 123,
  "sql_query": "<string>"
}
'
import requests

url = "https://api.vantage.sh/v2/billing_rules"

payload = {
"title": "<string>",
"start_period": "<string>",
"start_date": "<string>",
"end_date": "<string>",
"apply_to_all": True,
"charge_type": "<string>",
"percentage": 123,
"service": "<string>",
"category": "<string>",
"sub_category": "<string>",
"amount": 123,
"sql_query": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
title: '<string>',
start_period: '<string>',
start_date: '<string>',
end_date: '<string>',
apply_to_all: true,
charge_type: '<string>',
percentage: 123,
service: '<string>',
category: '<string>',
sub_category: '<string>',
amount: 123,
sql_query: '<string>'
})
};

fetch('https://api.vantage.sh/v2/billing_rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.vantage.sh/v2/billing_rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'title' => '<string>',
'start_period' => '<string>',
'start_date' => '<string>',
'end_date' => '<string>',
'apply_to_all' => true,
'charge_type' => '<string>',
'percentage' => 123,
'service' => '<string>',
'category' => '<string>',
'sub_category' => '<string>',
'amount' => 123,
'sql_query' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.vantage.sh/v2/billing_rules"

payload := strings.NewReader("{\n \"title\": \"<string>\",\n \"start_period\": \"<string>\",\n \"start_date\": \"<string>\",\n \"end_date\": \"<string>\",\n \"apply_to_all\": true,\n \"charge_type\": \"<string>\",\n \"percentage\": 123,\n \"service\": \"<string>\",\n \"category\": \"<string>\",\n \"sub_category\": \"<string>\",\n \"amount\": 123,\n \"sql_query\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.vantage.sh/v2/billing_rules")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"title\": \"<string>\",\n \"start_period\": \"<string>\",\n \"start_date\": \"<string>\",\n \"end_date\": \"<string>\",\n \"apply_to_all\": true,\n \"charge_type\": \"<string>\",\n \"percentage\": 123,\n \"service\": \"<string>\",\n \"category\": \"<string>\",\n \"sub_category\": \"<string>\",\n \"amount\": 123,\n \"sql_query\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.vantage.sh/v2/billing_rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"title\": \"<string>\",\n \"start_period\": \"<string>\",\n \"start_date\": \"<string>\",\n \"end_date\": \"<string>\",\n \"apply_to_all\": true,\n \"charge_type\": \"<string>\",\n \"percentage\": 123,\n \"service\": \"<string>\",\n \"category\": \"<string>\",\n \"sub_category\": \"<string>\",\n \"amount\": 123,\n \"sql_query\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "token": "bllng_rule_9cc9eab6bb73266b",
  "title": "Credit for Data Transfer",
  "type": "Credit",
  "created_by_token": "usr_ae0b14f6c9108edc",
  "created_at": "2024-07-02T15:26:52Z",
  "service": "Amazon S3",
  "category": "Data Transfer",
  "sub_category": "Outbound",
  "start_period": "2024-05-01",
  "amount": "300.0"
}
{
"errors": [
"<string>"
],
"links": {
"self": "<string>",
"first": "<string>",
"next": "<string>",
"last": "<string>",
"prev": "<string>"
}
}

Authorizations

Authorization
string
header
required

The access token received from the authorization server in the OAuth 2.0 flow.

Body

application/json

Create a BillingRule.

type
enum<string>
required

The type of the BillingRule. Note: the values are case insensitive.

Available options:
exclusion,
adjustment,
credit,
charge,
custom
title
string
required

The title of the BillingRule.

start_period
string

The start period of the BillingRule. DEPRECATED: use start_date instead.

start_date
string

The start date of the BillingRule. ISO 8601 formatted.

end_date
string

The end date of the BillingRule. ISO 8601 formatted.

apply_to_all
boolean

Determines if the BillingRule applies to all current and future managed accounts.

charge_type
string

The charge type of the BillingRule. Required for Exclusion rules.

percentage
number<double>

The percentage of the cost shown. Required for Adjustment rules. Example value: 75.0

service
string

The service of the BillingRule. Required for Charge and Credit rules.

category
string

The category of the BillingRule. Required for Charge and Credit rules.

sub_category
string

The subcategory of the BillingRule. Required for Charge and Credit rules.

amount
number<double>

The amount for the BillingRule. Required for Charge and Credit rules. Example value: 300

sql_query
string

The SQL query for the BillingRule. Required for Custom rules. Example value: UPDATE costs SET costs.amount = costs.amount * 0.95

Response

BillingRule model

token
string
required
title
string
required

The title of the BillingRule.

Example:

"Credit for Unused EC2 Instances"

type
string
required

The type of the BillingRule.

Example:

"credit"

apply_to_all
boolean | null
required

Whether the BillingRule applies to all future managed accounts.

Example:

true

created_by_token
string
required

The token of the Creator of the BillingRule.

Example:

"usr_1234"

created_at
string
required

The date and time, in UTC, the BillingRule was created. ISO 8601 Formatted.

Example:

"2024-06-28T00:00:00Z"

start_date
string | null

The start date of the BillingRule.

Example:

"2024-06-28T00:00:00Z"

end_date
string | null

The end date of the BillingRule.

Example:

"2024-06-28T00:00:00Z"

service
string | null

The service for the BillingRule (Charge).

Example:

"AWS Cloudfront"

category
string | null

The category for the BillingRule (Charge).

Example:

"MSP Fee"

percentage
string | null

The percentage of the cost shown for the BillingRule (Adjustment).

Example:

"75.0"

charge_type
string | null

The charge type for the BillingRule.

Example:

"RIFee"

sub_category
string | null

The subcategory for the BillingRule (Charge).

Example:

"One-time"

start_period
string | null

The start period for the BillingRule (Charge).

Example:

"2024-05-01"

amount
string | null

The amount for the BillingRule (Charge).

Example:

"5000.25"

sql_query
string | null

The SQL query for the BillingRule (Custom).

Example:

"UPDATE costs SET costs.amount = costs.amount * 0.95"