Skip to main content
POST
/
currencies
/
exchange-rates
Create a single exchange rate
curl --request POST \
  --url https://api.royalti.io/currencies/exchange-rates \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "base": "EUR",
  "quoted": "USD",
  "rate": 1.0842,
  "period": "202607",
  "source": "manual"
}
'
import requests

url = "https://api.royalti.io/currencies/exchange-rates"

payload = {
"base": "EUR",
"quoted": "USD",
"rate": 1.0842,
"period": "202607",
"source": "manual"
}
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({base: 'EUR', quoted: 'USD', rate: 1.0842, period: '202607', source: 'manual'})
};

fetch('https://api.royalti.io/currencies/exchange-rates', 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.royalti.io/currencies/exchange-rates",
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([
'base' => 'EUR',
'quoted' => 'USD',
'rate' => 1.0842,
'period' => '202607',
'source' => 'manual'
]),
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.royalti.io/currencies/exchange-rates"

payload := strings.NewReader("{\n \"base\": \"EUR\",\n \"quoted\": \"USD\",\n \"rate\": 1.0842,\n \"period\": \"202607\",\n \"source\": \"manual\"\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.royalti.io/currencies/exchange-rates")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"base\": \"EUR\",\n \"quoted\": \"USD\",\n \"rate\": 1.0842,\n \"period\": \"202607\",\n \"source\": \"manual\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.royalti.io/currencies/exchange-rates")

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 \"base\": \"EUR\",\n \"quoted\": \"USD\",\n \"rate\": 1.0842,\n \"period\": \"202607\",\n \"source\": \"manual\"\n}"

response = http.request(request)
puts response.read_body
{
  "status": "success",
  "message": "<string>",
  "data": {
    "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
    "TenantId": 123,
    "source": "manual",
    "period": "202607",
    "base": "EUR",
    "quoted": "USD",
    "rate": 1.0842,
    "effectiveDate": "2023-11-07T05:31:56Z",
    "expiryDate": "2023-11-07T05:31:56Z",
    "isDefault": true,
    "memo": "<string>",
    "createdAt": "2023-11-07T05:31:56Z",
    "updatedAt": "2023-11-07T05:31:56Z"
  }
}
{
"status": "error",
"message": "Validation failed",
"errors": [
"Base and quoted currencies must be different",
"Period must be in YYYYMM format with valid month (01-12)"
]
}
{
"status": "error",
"message": "<string>",
"code": "<string>",
"details": {}
}
This endpoint requires authentication. Include your Bearer token in the Authorization header.

Description

POST /currencies/exchange-rates Validated via the shared validateExchangeRateInput helper: both currency codes must be valid ISO 4217 codes and differ from each other, rate must be a positive number, and period must be YYYYMM with a valid month. Authorization: admin or higher (requireAdmin).

Code Examples

const response = await fetch('https://api.royalti.io/currencies/exchange-rates', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "ref": "#/components/schemas/ExchangeRateInput"
  })
});

const data = await response.json();
console.log(data);
import requests

response = requests.post(
  'https://api.royalti.io/currencies/exchange-rates',
  headers={
    'Authorization': f'Bearer {token}'
  },
  json={"ref":"#/components/schemas/ExchangeRateInput"}
)

data = response.json()
print(data)
curl -X POST https://api.royalti.io/currencies/exchange-rates \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ref":"#/components/schemas/ExchangeRateInput"}'

Authorizations

Authorization
string
header
required

JWT Authorization header using the Bearer scheme. Format: "Bearer {token}"

Body

application/json
base
string
required

ISO 4217 base currency code.

Example:

"EUR"

quoted
string
required

ISO 4217 quoted currency code.

Example:

"USD"

rate
number
required
Required range: x > 0
period
string
required

YYYYMM, month 01-12.

Pattern: ^\d{6}$
Example:

"202607"

source
string
default:manual
effectiveDate
string<date-time>
expiryDate
string<date-time>
isDefault
boolean
default:false
memo
string

Response

Exchange rate created

status
string
Example:

"success"

message
string
data
object

A stored exchange rate (ExchangeRate model).