2 min read
List products
require 'net/http'
require 'json'
require 'uri'
BASE = 'https://api.credicorp.co.uk/public/v1'
def list_products
uri = URI("#{BASE}/products")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 10) do |http|
http.get(uri.request_uri, 'Accept' => 'application/json')
end
body = JSON.parse(res.body, symbolize_names: true)
if res.code.to_i >= 400
e = body[:error] || {}
raise "#{res.code} #{e[:code]}: #{e[:message]}"
end
body[:data]
end
list_products.each do |p|
puts "#{p[:name]} \u2014 up to \u00a3#{p[:max_amount]}"
end
With Faraday
If your app uses Faraday, the same request is shorter and gives you middleware for retries and JSON parsing:
conn = Faraday.new(url: BASE) { |f| f.response :json }
data = conn.get('products').body['data']
Frequently asked questions
Should I use a gem?
For the public ring, no — net/http is enough. Faraday or HTTParty are fine if your app already depends on them and you want retry middleware.
How do I set a timeout?
Pass read_timeout and open_timeout to Net::HTTP.start, as shown. Never leave a request without a timeout in a web request cycle.
Related reading

Quickstart: your first Credicorp public API call with curl
The fastest way to see the Credicorp public API working is a single curl call to GET /public/v1/products. The…
Read →
Quickstart: call the Credicorp public API from PHP
You can call the Credicorp public API from PHP with the built-in cURL extension and no Composer packages…
Read →
Quickstart: call the Credicorp public API from Python
With the requests library you can call the Credicorp public API in about ten lines of Python. This quickstart…
Read →
Quickstart: call the Credicorp public API from Node.js
Node 18+ ships a global fetch, so you can call the Credicorp public API with zero dependencies. This…
Read →Funding for UK limited companies
Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.