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 axios = require('axios');
const apiKey = 'cp_live_your_api_key';
const apiSecret = 'cs_live_your_api_secret';
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'
};
axios.post('https://api.consentproof.io/api/v1/policies', body, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey,
'X-API-Secret': apiSecret
}
}).then(res => {
console.log(res.data);
// Save the policy ID for recording consent
const policyId = res.data.data.id;
});Response:
Responsejson
{
"success": true,
"data": {
"id": "542ecac6-0ca1-47aa-a0a5-0585080602d5",
"policyType": "privacy_policy",
"version": "1.0.0",
"title": "Privacy Policy",
"contentHash": "a1b2c3d4e5f6...",
"isActive": true,
"createdAt": "2024-01-15T10:30:00Z"
}
}3
Record Consent
When a user grants consent, record the event:
Record consent (Node.js)javascript
const axios = require('axios');
const apiKey = 'cp_live_your_api_key';
const apiSecret = 'cs_live_your_api_secret';
const body = {
policyVersionId: '542ecac6-0ca1-47aa-a0a5-0585080602d5', // From policy creation
userReference: 'user_123', // Your unique user identifier
consentGiven: true,
metadata: {
source: 'signup_form'
}
};
axios.post('https://api.consentproof.io/api/v1/consent', body, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey,
'X-API-Secret': apiSecret
}
}).then(res => console.log(res.data));Response:
Responsejson
{
"success": true,
"data": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"policyVersionId": "542ecac6-0ca1-47aa-a0a5-0585080602d5",
"userReference": "user_123",
"consentGiven": true,
"consentHash": "a1b2c3d4e5f6...",
"timestamp": "2024-01-15T10:35:00Z"
}
}Note: The consentHash is a cryptographic proof of the consent record. This can be used to verify the record hasn't been tampered with.
4
Verify Consent
Check if a user has valid consent before processing their data:
Verify consentbash
curl -X GET "https://api.consentproof.io/api/v1/consent/123e4567-e89b-12d3-a456-426614174000/verify" \
-H "X-API-Key: cp_live_your_api_key" \
-H "X-API-Secret: cs_live_your_api_secret"Response:
Responsejson
{
"success": true,
"data": {
"valid": true,
"consentId": "123e4567-e89b-12d3-a456-426614174000",
"storedHash": "a1b2c3d4e5f6...",
"computedHash": "a1b2c3d4e5f6...",
"verifiedAt": "2024-01-15T10:40:00Z"
}
}Next Steps
Now that you've recorded your first consent, explore more features: