5 minute read
Quickstart
Learn how to integrate ConsentProof into your application in under 5 minutes.
Prerequisites
Before you begin, make sure you have:
- A ConsentProof account (sign up free)
- An API key from your dashboard
- Node.js 18+ (for JavaScript) or any HTTP client
1
Get Your API Key
First, get your API key from the ConsentProof dashboard:
- Log in to your ConsentProof dashboard
- Navigate to API Keys in the sidebar
- Click Create API Key
- Copy your API key and secret (you'll only see the secret once!)
Important: Keep your API secret secure. Never expose it in client-side code or commit it to version control.
2
Create a Policy
Create a policy to represent the document users will consent to (e.g., privacy policy, terms of service).
Create a policy (Node.js)javascript
const crypto = require('crypto');
const axios = require('axios');
const apiKey = 'your_api_key_here';
const method = 'POST';
const path = '/api/v1/policies';
const timestamp = Date.now().toString();
const body = {
policyType: 'privacy_policy',
version: '1.0.0',
title: 'Privacy Policy',
content: 'Your privacy policy content here...',
effectiveDate: '2024-01-01T00:00:00.000Z'
};
const bodyString = JSON.stringify(body);
const payload = `${method}|${path}|${timestamp}|${bodyString}`;
const signature = crypto
.createHmac('sha256', apiKey)
.update(payload)
.digest('hex');
axios.post('https://api.consentproof.io/api/v1/policies', body, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey,
'X-Timestamp': timestamp,
'X-Signature': signature
}
}).then(res => console.log(res.data));Response:
Responsejson
{
"success": true,
"data": {
"id": "pol_abc123",
"name": "Privacy Policy",
"type": "privacy_policy",
"version": "1.0",
"is_active": true,
"created_at": "2024-01-15T10:30:00Z"
}
}3
Record Consent
When a user grants consent, record the event:
Record consent (Node.js)javascript
const crypto = require('crypto');
const axios = require('axios');
const apiKey = 'your_api_key_here';
const method = 'POST';
const path = '/api/v1/consent';
const timestamp = Date.now().toString();
const body = {
policyVersionId: 'uuid-from-policy-creation',
userReference: 'user_123',
userEmail: 'user@example.com',
consentGiven: true,
ipAddress: '192.168.1.1',
userAgent: 'Mozilla/5.0...'
};
const bodyString = JSON.stringify(body);
const payload = `${method}|${path}|${timestamp}|${bodyString}`;
const signature = crypto
.createHmac('sha256', apiKey)
.update(payload)
.digest('hex');
axios.post('https://api.consentproof.io/api/v1/consent', body, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey,
'X-Timestamp': timestamp,
'X-Signature': signature
}
}).then(res => console.log(res.data));Response:
Responsejson
{
"success": true,
"data": {
"id": "con_xyz789",
"subject_id": "user_123",
"policy_id": "pol_abc123",
"consent_type": "privacy_policy",
"granted": true,
"consent_hash": "sha256:a1b2c3d4e5f6...",
"recorded_at": "2024-01-15T10:35:00Z"
}
}Note: The consent_hash is a cryptographic proof of the consent record. Store this for verification purposes.
4
Verify Consent
Check if a user has valid consent before processing their data:
Verify consentbash
curl -X GET "https://api.consentproof.io/v1/consent/verify?subject_id=user_123&consent_type=privacy_policy" \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_api_secret"Response:
Responsejson
{
"success": true,
"data": {
"has_consent": true,
"consent": {
"id": "con_xyz789",
"granted": true,
"policy_version": "1.0",
"recorded_at": "2024-01-15T10:35:00Z"
}
}
}Next Steps
Now that you've recorded your first consent, explore more features: