Skip to main content
POST
/
v1
/
contracts
/
customerCredits
/
create
Create a credit
curl --request POST \
  --url https://api.metronome.com/v1/contracts/customerCredits/create \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "customer_id": "13117714-3f05-48e5-a6e9-a66093f13b4d",
  "name": "My Credit",
  "priority": 100,
  "product_id": "f14d6729-6a44-4b13-9908-9387f1918790",
  "access_schedule": {
    "credit_type_id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
    "schedule_items": [
      {
        "amount": 1000,
        "starting_at": "2020-01-01T00:00:00.000Z",
        "ending_before": "2020-02-01T00:00:00.000Z"
      }
    ]
  }
}
'
import requests

url = "https://api.metronome.com/v1/contracts/customerCredits/create"

payload = {
"customer_id": "13117714-3f05-48e5-a6e9-a66093f13b4d",
"name": "My Credit",
"priority": 100,
"product_id": "f14d6729-6a44-4b13-9908-9387f1918790",
"access_schedule": {
"credit_type_id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"schedule_items": [
{
"amount": 1000,
"starting_at": "2020-01-01T00:00:00.000Z",
"ending_before": "2020-02-01T00:00:00.000Z"
}
]
}
}
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({
customer_id: '13117714-3f05-48e5-a6e9-a66093f13b4d',
name: 'My Credit',
priority: 100,
product_id: 'f14d6729-6a44-4b13-9908-9387f1918790',
access_schedule: {
credit_type_id: '2714e483-4ff1-48e4-9e25-ac732e8f24f2',
schedule_items: [
{
amount: 1000,
starting_at: '2020-01-01T00:00:00.000Z',
ending_before: '2020-02-01T00:00:00.000Z'
}
]
}
})
};

fetch('https://api.metronome.com/v1/contracts/customerCredits/create', 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.metronome.com/v1/contracts/customerCredits/create",
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([
'customer_id' => '13117714-3f05-48e5-a6e9-a66093f13b4d',
'name' => 'My Credit',
'priority' => 100,
'product_id' => 'f14d6729-6a44-4b13-9908-9387f1918790',
'access_schedule' => [
'credit_type_id' => '2714e483-4ff1-48e4-9e25-ac732e8f24f2',
'schedule_items' => [
[
'amount' => 1000,
'starting_at' => '2020-01-01T00:00:00.000Z',
'ending_before' => '2020-02-01T00:00:00.000Z'
]
]
]
]),
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.metronome.com/v1/contracts/customerCredits/create"

payload := strings.NewReader("{\n \"customer_id\": \"13117714-3f05-48e5-a6e9-a66093f13b4d\",\n \"name\": \"My Credit\",\n \"priority\": 100,\n \"product_id\": \"f14d6729-6a44-4b13-9908-9387f1918790\",\n \"access_schedule\": {\n \"credit_type_id\": \"2714e483-4ff1-48e4-9e25-ac732e8f24f2\",\n \"schedule_items\": [\n {\n \"amount\": 1000,\n \"starting_at\": \"2020-01-01T00:00:00.000Z\",\n \"ending_before\": \"2020-02-01T00:00:00.000Z\"\n }\n ]\n }\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.metronome.com/v1/contracts/customerCredits/create")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"13117714-3f05-48e5-a6e9-a66093f13b4d\",\n \"name\": \"My Credit\",\n \"priority\": 100,\n \"product_id\": \"f14d6729-6a44-4b13-9908-9387f1918790\",\n \"access_schedule\": {\n \"credit_type_id\": \"2714e483-4ff1-48e4-9e25-ac732e8f24f2\",\n \"schedule_items\": [\n {\n \"amount\": 1000,\n \"starting_at\": \"2020-01-01T00:00:00.000Z\",\n \"ending_before\": \"2020-02-01T00:00:00.000Z\"\n }\n ]\n }\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.metronome.com/v1/contracts/customerCredits/create")

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 \"customer_id\": \"13117714-3f05-48e5-a6e9-a66093f13b4d\",\n \"name\": \"My Credit\",\n \"priority\": 100,\n \"product_id\": \"f14d6729-6a44-4b13-9908-9387f1918790\",\n \"access_schedule\": {\n \"credit_type_id\": \"2714e483-4ff1-48e4-9e25-ac732e8f24f2\",\n \"schedule_items\": [\n {\n \"amount\": 1000,\n \"starting_at\": \"2020-01-01T00:00:00.000Z\",\n \"ending_before\": \"2020-02-01T00:00:00.000Z\"\n }\n ]\n }\n}"

response = http.request(request)
puts response.read_body
{
  "data": {
    "id": "6162d87b-e5db-4a33-b7f2-76ce6ead4e85"
  }
}
{
"message": "<string>"
}
{
"message": "<string>"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Create a credit

customer_id
string<uuid>
required
priority
number
required

If multiple credits or commits are applicable, the one with the lower priority will apply first.

product_id
string<uuid>
required
access_schedule
object
required

Schedule for distributing the credit to the customer.

name
string

displayed on invoices

Minimum string length: 1
description
string

Used only in UI/API. It is not exposed to end customers.

applicable_product_ids
string<uuid>[]

Which products the credit applies to. If both applicable_product_ids and applicable_product_tags are not provided, the credit applies to all products.

applicable_product_tags
string[]

Which tags the credit applies to. If both applicable_product_ids and applicable_product_tags are not provided, the credit applies to all products.

specifiers
object[]

List of filters that determine what kind of customer usage draws down a commit or credit. A customer's usage needs to meet the condition of at least one of the specifiers to contribute to a commit's or credit's drawdown. This field cannot be used together with applicable_product_ids or applicable_product_tags.

applicable_contract_ids
string[]

Which contract the credit applies to. If not provided, the credit applies to all contracts.

custom_fields
object

Custom fields to be added eg. { "key1": "value1", "key2": "value2" }

rate_type
enum<string>
Available options:
COMMIT_RATE,
commit_rate,
LIST_RATE,
list_rate
uniqueness_key
string

Prevents the creation of duplicates. If a request to create a commit or credit is made with a uniqueness key that was previously used to create a commit or credit, a new record will not be created and the request will fail with a 409 error.

Required string length: 1 - 128

Response

Success

data
object
required