التحقق من صحة رمز الوصول
curl --request GET \
--url https://api.oneclickdz.com/v3/validate \
--header 'X-Access-Token: <api-key>'import requests
url = "https://api.oneclickdz.com/v3/validate"
headers = {"X-Access-Token": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-Access-Token': '<api-key>'}};
fetch('https://api.oneclickdz.com/v3/validate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.oneclickdz.com/v3/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Access-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.oneclickdz.com/v3/validate"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Access-Token", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.oneclickdz.com/v3/validate")
.header("X-Access-Token", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.oneclickdz.com/v3/validate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Access-Token"] = '<api-key>'
response = http.request(request)
puts response.read_bodyCore
التحقق من صحة رمز الوصول
التحقق من صحة مفتاح API الخاص بك والحصول على معلومات الحساب
GET
/
v3
/
validate
التحقق من صحة رمز الوصول
curl --request GET \
--url https://api.oneclickdz.com/v3/validate \
--header 'X-Access-Token: <api-key>'import requests
url = "https://api.oneclickdz.com/v3/validate"
headers = {"X-Access-Token": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-Access-Token': '<api-key>'}};
fetch('https://api.oneclickdz.com/v3/validate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.oneclickdz.com/v3/validate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-Access-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.oneclickdz.com/v3/validate"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Access-Token", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.oneclickdz.com/v3/validate")
.header("X-Access-Token", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.oneclickdz.com/v3/validate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Access-Token"] = '<api-key>'
response = http.request(request)
puts response.read_bodyنظرة عامة
يتيح لك endpoint التحقق من الصحة التأكد من أن مفتاح API الخاص بك صالح واسترداد المعلومات المتعلقة بالحساب المرتبط وصلاحيات المفتاح.يُعدّ هذا endpoint مفيدًا للتحقق من صلاحية مفتاح API عند بدء تشغيل التطبيق
أو بعد تدوير المفتاح.
الاستجابة
boolean
مطلوب
true إذا نجح التحققobject
مطلوب
إظهار properties
إظهار properties
string
اسم المستخدم المرتبط بمفتاح API
مثال على الطلب
curl --request GET \
--url https://api.oneclickdz.com/v3/validate \
--header 'X-Access-Token: YOUR_API_KEY'
const response = await fetch("https://api.oneclickdz.com/v3/validate", {
headers: {
"X-Access-Token": process.env.ONECLICKDZ_API_KEY,
},
});
const data = await response.json();
if (data.success) {
console.log("✓ API key is valid");
console.log("Account:", data.data.username);
console.log("Type:", data.data.apiKey.type);
} else {
console.error("✗ API key validation failed");
}
import requests
import os
response = requests.get(
'https://api.oneclickdz.com/v3/validate',
headers={'X-Access-Token': os.getenv('ONECLICKDZ_API_KEY')}
)
data = response.json()
if data['success']:
print('✓ API key is valid')
print(f"Account: {data['data']['username']}")
print(f"Type: {data['data']['apiKey']['type']}")
else:
print('✗ API key validation failed')
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.oneclickdz.com/v3/validate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Access-Token: ' . getenv('ONECLICKDZ_API_KEY')
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['success']) {
echo "✓ API key is valid\n";
echo "Account: " . $data['data']['username'] . "\n";
echo "Type: " . $data['data']['apiKey']['type'] . "\n";
} else {
echo "✗ API key validation failed\n";
}
?>
مثال على الاستجابة
{
"success": true,
"data": {
"username": "+213665983439",
"apiKey": {
"key": "ea27b376-9f5c-4b09-883f-1b96cd7b541c",
"isEnabled": true,
"type": "SANDBOX",
"allowedips": [],
"scope": "READ-WRITE"
}
}
}
استجابات الخطأ
400 - رمز الوصول مفقود
400 - رمز الوصول مفقود
{
"success": false,
"error": {
"code": "MISSING_ACCESS_TOKEN",
"message": "Access token is required"
},
"requestId": "req_abc123"
}
401 - رمز الوصول غير صالح
401 - رمز الوصول غير صالح
{
"success": false,
"error": {
"code": "INVALID_ACCESS_TOKEN",
"message": "The provided access token is invalid",
"details": {
"attemptsLeft": 3
}
},
"requestId": "req_abc123"
}
بعد 5 محاولات فاشلة، سيُحظر عنوان IP الخاص بك مؤقتًا لمدة 15 دقيقة.
403 - IP محظور
403 - IP محظور
{
"success": false,
"error": {
"code": "IP_BLOCKED",
"message": "Your IP has been temporarily blocked due to too many invalid attempts"
},
"requestId": "req_abc123"
}
حالات الاستخدام
التحقق عند بدء التشغيل
تحقق من مفتاح API عند تهيئة التطبيق
فحوصات الصحة
أدرجه في روتينات فحص صحة التطبيق
التحقق من البيئة
تأكد من استخدام المفتاح الصحيح (sandbox مقابل الإنتاج)
التحقق من الصلاحيات
تحقق من نطاق المفتاح وصلاحياته قبل العمليات
مثال على التكامل
class OneClickDzClient {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = "https://api.oneclickdz.com";
this.validated = false;
}
async validate() {
const response = await fetch(`${this.baseUrl}/v3/validate`, {
headers: { "X-Access-Token": this.apiKey },
});
const data = await response.json();
if (!data.success) {
throw new Error(`API key validation failed: ${data.error.message}`);
}
this.username = data.data.username;
this.keyType = data.data.apiKey.type;
this.scope = data.data.apiKey.scope;
this.validated = true;
console.log(`✓ Authenticated as ${this.username} (${this.keyType})`);
return data.data;
}
async request(endpoint, options = {}) {
if (!this.validated) {
await this.validate();
}
if (
options.method &&
options.method !== "GET" &&
this.scope === "READ-ONLY"
) {
throw new Error("This operation requires READ-WRITE access");
}
return fetch(`${this.baseUrl}${endpoint}`, {
...options,
headers: {
...options.headers,
"X-Access-Token": this.apiKey,
},
});
}
}
// Usage
const client = new OneClickDzClient(process.env.ONECLICKDZ_API_KEY);
await client.validate();
أفضل الممارسات
التحقق عند بدء التشغيل
التحقق عند بدء التشغيل
تحقق دائمًا من مفتاح API عند بدء تشغيل التطبيق
// During app initialization
async function initializeApp() {
try {
await client.validate();
console.log('✓ API client initialized');
} catch (error) {
console.error('✗ Failed to initialize API client:', error);
process.exit(1);
}
}
تخزين نتيجة التحقق مؤقتًا
تخزين نتيجة التحقق مؤقتًا
لا تتحقق في كل طلب - خزّن النتيجة مؤقتًا
let validationCache = {
validated: false,
timestamp: 0,
data: null
};
async function getValidatedClient() {
const now = Date.now();
const cacheExpiry = 5 * 60 * 1000; // 5 minutes
if (validationCache.validated && (now - validationCache.timestamp) < cacheExpiry) {
return validationCache.data;
}
const response = await fetch('https://api.oneclickdz.com/v3/validate', {
headers: { 'X-Access-Token': API_KEY }
});
const data = await response.json();
if (data.success) {
validationCache = {
validated: true,
timestamp: now,
data: data.data
};
}
return data.data;
}
التحقق من البيئة
التحقق من البيئة
تحقق من أنك تستخدم البيئة الصحيحة
const data = await validateApiKey();
const isProduction = process.env.NODE_ENV === 'production';
const keyType = data.apiKey.type;
if (isProduction && keyType === 'SANDBOX') {
throw new Error('⚠️ Using SANDBOX key in production environment!');
}
if (!isProduction && keyType === 'PRODUCTION') {
console.warn('⚠️ Using PRODUCTION key in development environment!');
}
المعالجة بلطف
المعالجة بلطف
نفّذ معالجة الأخطاء بشكل صحيح
async function validateWithRetry(maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch('https://api.oneclickdz.com/v3/validate', {
headers: { 'X-Access-Token': API_KEY }
});
const data = await response.json();
if (data.success) {
return data.data;
}
if (data.error.code === 'INVALID_ACCESS_TOKEN') {
throw new Error('Invalid API key - check your configuration');
}
if (data.error.code === 'IP_BLOCKED') {
throw new Error('IP blocked - too many failed attempts');
}
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
}
}
}
Endpoints ذات الصلة
فحص الصحة
التحقق من حالة خدمة API
الحصول على الرصيد
التحقق من رصيد حسابك
⌘I

