Docs

# Authorization

ReincarcarePrePay uses API keys to authenticate and authorize access to its API. You received your unique authorization key during onboarding. In this documentation, the key is referenced as [STAGING_API_KEY] or [PROD_API_KEY].

To use the API, include your API key in the headers of all requests to the server, using the X-Authorization header.

# Testing Your Authorization Key

Use the code samples below to verify your authorization key. The request is sent to the /v1/ping endpoint.

# Staging

curl -X POST "https://api-staging.reincarcareprepay.ro/v1/ping" \
     -H "X-Authorization: [STAGING_API_KEY]" \
     -H "Content-Type: application/json"
try {
    const res = await fetch("https://api-staging.reincarcareprepay.ro/v1/ping", {
        method: "POST",
        headers: {
            "X-Authorization": "[STAGING_API_KEY]",
            "Content-Type": "application/json"
        }
    })
    const json = await res.json()
    console.log(json)
} catch(err) {
    console.log(err)
}
<?php

$apiUrl = "https://api-staging.reincarcareprepay.ro/v1/ping";
$apiKey = "[STAGING_API_KEY]";

try {
    $ch = curl_init($apiUrl);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "X-Authorization: $apiKey",
        "Content-Type: application/json"
    ]);

    $response = curl_exec($ch);

    if(curl_errno($ch)) {
        throw new Exception(curl_error($ch));
    }

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

    if($httpCode !== 200) {
        throw new Exception("Request failed with status code: $httpCode");
    }

    $json = json_decode($response, true);
    print_r($json);
} catch(Exception $e) {
    echo "Error: " . $e->getMessage();
}

# Production

curl -X POST "https://api.reincarcareprepay.ro/v1/ping" \
     -H "X-Authorization: [PROD_API_KEY]" \
     -H "Content-Type: application/json"
try {
    const res = await fetch("https://api.reincarcareprepay.ro/v1/ping", {
        method: "POST",
        headers: {
            "X-Authorization": "[PROD_API_KEY]",
            "Content-Type": "application/json"
        }
    })
    const json = await res.json()
    console.log(json)
} catch(err) {
    console.log(err)
}
<?php

$apiUrl = "https://api.reincarcareprepay.ro/v1/ping";
$apiKey = "[PROD_API_KEY]";

try {
    $ch = curl_init($apiUrl);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "X-Authorization: $apiKey",
        "Content-Type: application/json"
    ]);

    $response = curl_exec($ch);

    if(curl_errno($ch)) {
        throw new Exception(curl_error($ch));
    }

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

    if($httpCode !== 200) {
        throw new Exception("Request failed with status code: $httpCode");
    }

    $json = json_decode($response, true);
    print_r($json);
} catch(Exception $e) {
    echo "Error: " . $e->getMessage();
}

If everything is set up correctly, you will receive the following response:

{ "pong": true }