Skip to content

Instantly share code, notes, and snippets.

@jhackett1
Last active August 28, 2024 12:43
Show Gist options
  • Save jhackett1/86891f384ce0311a70d8a32fcc2079f7 to your computer and use it in GitHub Desktop.
Save jhackett1/86891f384ce0311a70d8a32fcc2079f7 to your computer and use it in GitHub Desktop.
How to call the live Vouchsafe API using node.js
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment