Intégration API
Token Guard propose une API REST complète pour intégrer nos services de certification dans votre application.
Authentification
Toutes les requêtes API nécessitent une clé API :
const API_KEY = 'your-api-key';
const headers = {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
};Endpoints principaux
Créer une certification
POST /api/v1/certifications
// Request body
{
"watch": {
"brand": "Rolex",
"model": "Submariner",
"serialNumber": "12345678",
"year": 2020
},
"documents": [
"base64_encoded_image_1",
"base64_encoded_image_2"
]
}
// Response
{
"id": "cert_123456",
"status": "pending_validation",
"createdAt": "2024-10-02T10:00:00Z"
}Consulter une certification
GET /api/v1/certifications/:id
// Response
{
"id": "cert_123456",
"status": "validated",
"watch": {
"brand": "Rolex",
"model": "Submariner",
"serialNumber": "12345678"
},
"nft": {
"tokenId": "1234",
"contract": "0x...",
"blockchain": "lineaj"
},
"validations": [
{
"validator": "Expert Horloger",
"status": "approved",
"date": "2024-10-03T14:30:00Z"
}
]
}Vérifier un certificat
GET /api/v1/verify/:tokenId
// Response
{
"valid": true,
"certificate": {
"tokenId": "1234",
"watch": {
"brand": "Rolex",
"model": "Submariner"
},
"owner": "0x...",
"certificationDate": "2024-10-03T15:00:00Z"
}
}Webhooks
Recevez des notifications en temps réel :
// Configuration du webhook
POST /api/v1/webhooks
{
"url": "https://your-app.com/webhook",
"events": [
"certification.created",
"certification.validated",
"certification.rejected"
]
}
// Payload reçu
{
"event": "certification.validated",
"data": {
"certificationId": "cert_123456",
"timestamp": "2024-10-03T15:00:00Z"
}
}Exemples d'intégration
React/Next.js
'use client';
import { useState } from 'react';
export function CertificationForm() {
const [loading, setLoading] = useState(false);
const handleSubmit = async (data: FormData) => {
setLoading(true);
try {
const response = await fetch('/api/v1/certifications', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.NEXT_PUBLIC_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
const result = await response.json();
console.log('Certification créée:', result);
} catch (error) {
console.error('Erreur:', error);
} finally {
setLoading(false);
}
};
return (
<form onSubmit={handleSubmit}>
{/* Form fields */}
</form>
);
}Node.js
const axios = require('axios');
const tokenGuard = axios.create({
baseURL: 'https://api.tokenguard.com',
headers: {
'Authorization': `Bearer ${process.env.TOKEN_GUARD_API_KEY}`,
},
});
async function createCertification(watchData) {
try {
const response = await tokenGuard.post('/api/v1/certifications', {
watch: watchData,
});
return response.data;
} catch (error) {
console.error('Erreur:', error.response.data);
throw error;
}
}Limites et quotas
| Plan | Requêtes/heure | Certifications/mois | |------|----------------|---------------------| | Free | 100 | 10 | | Pro | 1,000 | 100 | | Enterprise | Illimité | Illimité |
SDK officiels
Nous proposons des SDK pour :
- JavaScript/TypeScript
- Python
- Ruby
- PHP
Installation :
npm install @tokenguard/sdkUtilisation :
import { TokenGuard } from '@tokenguard/sdk';
const tg = new TokenGuard({
apiKey: process.env.TOKEN_GUARD_API_KEY,
});
const certification = await tg.certifications.create({
watch: {
brand: 'Rolex',
model: 'Submariner',
serialNumber: '12345678',
},
});Support
Pour toute question sur l'API :
- Documentation complète : docs.tokenguard.com
- Support : api@tokenguard.com
- Discord : discord.gg/tokenguard