Skip to main content

Code Examples

Integration examples in popular languages.

JavaScript / Node.js

Using Fetch (Browser/Node)

async function getFinanceOffers(loanAmount, deposit = 0) {
const response = await fetch('https://api.finmatch.io/v1/finance-quote', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.pk_apikey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
merchant_id: process.env.M000101,
partner_id: process.env.P000001,
loan_amount: loanAmount,
customer_deposit: deposit,
merchant_finance_url: 'https://yoursite.com/finance'
})
});

if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}

const data = await response.json();
return data.data.products;
}

// Usage
try {
const offers = await getFinanceOffers(5000, 500);
console.log('Available finance products:', offers);
} catch (error) {
console.error('Error fetching offers:', error);
}

Using Axios

const axios = require('axios');

async function getFinanceOffers(loanAmount, deposit = 0) {
try {
const response = await axios.post(
'https://api.finmatch.io/v1/finance-quote',
{
merchant_id: process.env.M000101,
partner_id: process.env.P000001,
loan_amount: loanAmount,
customer_deposit: deposit,
merchant_finance_url: 'https://yoursite.com/finance'
},
{
headers: {
'Authorization': `Bearer ${process.env.pk_apikey}`,
'Content-Type': 'application/json'
}
}
);

return response.data.data.products;
} catch (error) {
if (error.response) {
console.error('API error:', error.response.data);
}
throw error;
}
}

Python

Using Requests

import os
import requests

def get_finance_offers(loan_amount, deposit=0):
url = 'https://api.finmatch.io/v1/finance-quote'
headers = {
'Authorization': f'Bearer {os.getenv("pk_apikey")}',
'Content-Type': 'application/json'
}
payload = {
'merchant_id': os.getenv('M000101'),
'partner_id': os.getenv('P000001'),
'loan_amount': loan_amount,
'customer_deposit': deposit,
'merchant_finance_url': 'https://yoursite.com/finance'
}

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

return response.json()['data']['products']

# Usage
try:
offers = get_finance_offers(5000, 500)
print(f'Found {len(offers)} finance products')
for product in offers:
print(f" - {product['credit_product']}: £{product['monthly_repayment']}/month")
except requests.exceptions.RequestException as e:
print(f'Error: {e}')

PHP

<?php

function getFinanceOffers(float $loanAmount, float $deposit = 0): array
{
$url = 'https://api.finmatch.io/v1/finance-quote';
$payload = [
'merchant_id' => getenv('M000101'),
'partner_id' => getenv('P000001'),
'loan_amount' => $loanAmount,
'customer_deposit' => $deposit,
'merchant_finance_url'=> 'https://yoursite.com/finance'
];

$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('pk_apikey'),
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode($payload)
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode !== 200) {
throw new Exception("API error: HTTP $httpCode – $response");
}

$data = json_decode($response, true);
return $data['data']['products'];
}

// Usage
try {
$offers = getFinanceOffers(5000, 500);
echo "Found " . count($offers) . " finance offers\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}

Ruby

require 'net/http'
require 'json'

def get_finance_offers(loan_amount, deposit = 0)
uri = URI('https://api.finmatch.io/v1/finance-quote')

request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV['pk_apikey']}"
request['Content-Type'] = 'application/json'
request.body = {
merchant_id: ENV['M000101'],
partner_id: ENV['P000001'],
loan_amount: loan_amount,
customer_deposit: deposit,
merchant_finance_url: 'https://yoursite.com/finance'
}.to_json

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end

raise "API error: #{response.code}" unless response.is_a?(Net::HTTPSuccess)

JSON.parse(response.body)['data']['products']
end

# Usage
begin
offers = get_finance_offers(5000, 500)
puts "Found #{offers.length} finance products"
rescue StandardError => e
puts "Error: #{e.message}"
end

Environment Variables

All examples use environment variables for security. Create a .env file:

FINMATCH_API_KEY=pk_apikey
MERCHANT_ID=M000101
PARTNER_ID=P000001
Security

Never commit API keys to source control. Use environment variables or secret management systems.

Next Steps