Skip to main content

PHP Example

Use the v2 API in PHP projects, WordPress plugins or web apps.

<?php
const RBLXVALUE_KEY = 'your_key_here';
const RBLXVALUE_URL = 'https://api.rblxvalue.com/v2';

function rblx_api(string $path): array {
$ch = curl_init(RBLXVALUE_URL . $path);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-Api-Key: ' . RBLXVALUE_KEY],
CURLOPT_TIMEOUT => 5,
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
return is_array($data) ? $data : [];
}

Item lookup (slug or acronym)​

function rblx_get_item(string $ident): ?array {
return rblx_api('/items/' . urlencode($ident))['item'] ?? null;
}

$item = rblx_get_item('corrupt'); // also 'CORR'
if ($item) {
echo "{$item['name']}: " . number_format($item['value']) . " (demand: {$item['demand']}/10)\n";
echo "MM2Values {$item['value_source_a']} · Supreme {$item['value_source_b']}";
}

Set lookup​

function rblx_get_set(string $ident): ?array {
return rblx_api('/sets/' . urlencode($ident))['set'] ?? null;
}

$set = rblx_get_set('celestial'); // 'constellation' resolves to the same set
if ($set) {
echo "{$set['name']}: " . number_format($set['total_value']) . " total\n";
foreach ($set['items'] as $i) {
echo " - {$i['name']}: " . number_format($i['value']) . "\n";
}
}

Profile lookup​

function rblx_get_profile(string $username): ?array {
return rblx_api('/profile/' . urlencode($username))['profile'] ?? null;
}

$p = rblx_get_profile('UN6107617');
if ($p) {
echo "{$p['display_name']} — ";
echo $p['inventory_public'] ? number_format($p['total_value']) . " inventory value" : "Private inventory";
}

Trade calculator​

function rblx_trade_calc(array $yours, array $theirs): array {
$val = fn(string $ident): int => (int)(rblx_get_item($ident)['value'] ?? 0);
$yourTotal = array_sum(array_map($val, $yours));
$theirTotal = array_sum(array_map($val, $theirs));
return [
'your_total' => $yourTotal,
'their_total' => $theirTotal,
'difference' => $theirTotal - $yourTotal,
'fair' => abs($theirTotal - $yourTotal) / max($yourTotal, 1) < 0.1,
];
}

$r = rblx_trade_calc(['corrupt'], ['luger']);
echo $r['fair'] ? 'Fair trade' : 'Unfair trade';
echo ' (difference: ' . number_format($r['difference']) . ')';