Node.js
Here’s a minimal Node.js code sample showing how to interact with the API:
const ENDPOINT_HOST = "https://app.vouchsafe.id/api/v1"
// Step 1. Get client ID and secret from the dashboard
const CLIENT_ID = "YOUR_CLIENT_ID_HERE"
const CLIENT_SECRET = "YOUR_CLIENT_SECRET_HERE"
// Step 2. Trade client id and secret for a time-limited access token
const getAccessToken = async () => {
const res = await fetch(`${ENDPOINT_HOST}/authenticate`, {
method: "POST",
body: JSON.stringify({
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
}),
headers: {
"Content-Type": "application/json",
},
})
const data = await res.json()
return data.access_token
}
// Step 3. Call an endpoint
const getVerificationById = async id => {
const access_token = await getAccessToken()
const res = await fetch(`${ENDPOINT_HOST}/verifications/${id}`, {
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
})
const data = await res.json()
return data
}
// Step 4. Run the code
getVerificationById("YOUR_ID_HERE")
.then(data => console.log(data))
.catch(err => console.error(err))