Score-Based Filtering Examples

Use the risk_score or risk_level in your integration to automatically allow, review, or block users. Below are some examples in common programming languages.


🔹Node.js (using axios)

const axios = require('axios');

async function validateUser(data) {
  const response = await axios.post('https://api.onsefy.com/v1/validate/user', data, {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'X-Service-Id': 'YOUR_SERVICE_ID',
      'Content-Type': 'application/json'
    }
  });

  const result = response.data;
  if (result.summary.risk_score <= 2) {
    console.log("✅ Approved");
  } else if (result.summary.risk_score <= 5) {
    console.log("🟡 Needs Review");
  } else {
    console.log("❌ Blocked");
  }
}

🔹PHP (using Guzzle)

use GuzzleHttp\Client;

$client = new Client();
$response = $client->post('https://api.onsefy.com/v1/validate/user', [
    'headers' => [
        'Authorization' => 'Bearer YOUR_API_KEY',
        'X-Service-Id' => 'YOUR_SERVICE_ID',
        'Content-Type' => 'application/json',
    ],
    'json' => [
        'email' => 'user@gmail.com',
        'phone' => '+15551234567',
        'ip' => '35.242.177.6',
        'name' => 'John Doe',
        'user_agent' => $_SERVER['HTTP_USER_AGENT'],
    ]
]);

$data = json_decode($response->getBody(), true);
$riskScore = $data['summary']['risk_score'];

if ($riskScore <= 2) {
    echo "✅ Approved";
} elseif ($riskScore <= 5) {
    echo "🟡 Review";
} else {
    echo "❌ Block";
}

🔹Python (using requests)

import requests

headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "X-Service-Id": "YOUR_SERVICE_ID",
    "Content-Type": "application/json"
}

payload = {
    "email": "user@gmail.com",
    "phone": "+15551234567",
    "ip": "35.242.177.6",
    "name": "John Doe",
    "user_agent": "Mozilla/5.0"
}

response = requests.post("https://api.onsefy.com/v1/validate/user", json=payload, headers=headers)
data = response.json()

score = data['summary']['risk_score']
if score <= 2:
    print("✅ Approved")
elif score <= 5:
    print("🟡 Review")
else:
    print("❌ Blocked")

🔹cURL

curl --location 'https://api.onsefy.com/v1/validate/user' \
--header 'X-Service-Id: YOUR_SERVICE_ID' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "email": "user@gmail.com",
  "phone": "+15551234567",
  "ip": "35.242.177.6",
  "name": "John Doe",
  "user_agent": "Mozilla/5.0"
}'

⚠️ Note: Filter logic needs to be implemented in your code based on the returned JSON.