Quickstart

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. This quickstart performs GET /public/v1/products, decodes the JSON envelope into an array and shows the minimal error handling you need before wiring the response into a page or a Laravel controller.

2 min read

ext-curlNo Composer needed
8.1+Enums & readonly recommended
assocjson_decode as arrays

List products

A single cURL handle is enough for a read-only public call:

<?php
$base = 'https://api.credicorp.co.uk/public/v1';
$ch = curl_init($base . '/products');
curl_setopt_array($ch, [
    CURLOPT_RETURNURTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Accept: application/json'],
    CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$payload = json_decode($body, true);
if ($status >= 400) {
    $e = $payload['error'] ?? ['code' => 'unknown', 'message' => 'error'];
    throw new RuntimeException("{$status} {$e['code']}: {$e['message']}");
}
foreach ($payload['data'] as $product) {
    printf("%s \u2014 up to \u00a3%s\n", $product['name'], number_format($product['max_amount']));
}

Guzzle, if you already have it

If your project already depends on Guzzle, the same call is a two-liner and you get exceptions and timeouts for free:

$client = new \GuzzleHttp\Client(['base_uri' => $base, 'timeout' => 10]);
$data = json_decode($client->get('products')->getBody(), true)['data'];

Where to keep the base URL

Do not hard-code the host. In Laravel put it in config/services.php and read it with config('services.credicorp.base'); in plain PHP use an environment variable. Point it at https://sandbox.credicorp.co.uk/public/v1 in development.

Frequently asked questions

Do I need Guzzle?

No. The built-in ext-curl covers every public-ring call. Guzzle is convenient if you already use it, but it is not required for these read-only requests.

How do I verify TLS correctly?

Leave CURLOPT_SSL_VERIFYPEER at its default (true). Never disable certificate verification to work around a local CA issue — install the correct CA bundle instead.

Is there an official PHP SDK?

There is a PHP SDK for the partner ring documented under /sdks/php.html. For the public ring the raw cURL shown here is usually all you need.

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.