Skip to content

Commit 38777b4

Browse files
Merge pull request #5 from Incode-Technologies-Example-Repos/restoring-example-env
Restoring Missing sample.env and removed uneeded adminToken from score call
2 parents 3166664 + 19158d0 commit 38777b4

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

sample-server/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const defaultHeader = {
1818
'api-version': '1.0'
1919
};
2020

21-
// Admin Token + ApiKey are needed for approving and fetching scores
21+
// Admin Token + ApiKey are needed for approving
2222
const adminHeader = {
2323
'Content-Type': "application/json",
2424
'x-api-key': process.env.API_KEY,
@@ -86,12 +86,9 @@ app.get('/onboarding-url', async (req, res) => {
8686
}
8787
const {token, interviewId} = startData;
8888

89-
const onboardingHeader = {
90-
'Content-Type': "application/json",
91-
'X-Incode-Hardware-Id': startData.token,
92-
'x-api-key': process.env.API_KEY,
93-
'api-version': '1.0'
94-
};
89+
const onboardingHeader = {...defaultHeader};
90+
onboardingHeader['X-Incode-Hardware-Id'] = startData.token;
91+
9592
const onboardingUrl = `${process.env.API_URL}/0/omni/onboarding-url`;
9693

9794
let onboardingUrlData= null;
@@ -139,17 +136,19 @@ app.get('/fetch-score', async (req, res) => {
139136

140137
//Get the token of the session from the headers
141138
let token = req.headers["x-token"];
142-
if(!token) {
139+
if (!token) {
143140
res.status(400).send({success:false, error:'Missing required header X-Token'});
144141
return;
145142
}
146-
adminHeader['X-Incode-Hardware-Id'] = token;
143+
144+
scoreHeader = {...defaultHeader};
145+
scoreHeader['X-Incode-Hardware-Id'] = token;
147146

148147
//Let's find out the score
149148
const scoreUrl = `${process.env.API_URL}/omni/get/score`;
150149
let onboardingScore = null
151150
try {
152-
onboardingScore = await doGet(scoreUrl, {id:interviewId}, adminHeader);
151+
onboardingScore = await doGet(scoreUrl, {id:interviewId}, scoreHeader);
153152
} catch(e) {
154153
console.log(e.message);
155154
res.status(500).send({success:false, error: e.message});
@@ -405,6 +404,7 @@ const doPost = async (url, bodyparams, headers) => {
405404
try {
406405
const response = await fetch(url, { method: 'POST', body: JSON.stringify(bodyparams), headers});
407406
if (!response.ok) {
407+
//console.log(await response.json());
408408
throw new Error('Request failed with code ' + response.status)
409409
}
410410
return response.json();
@@ -417,6 +417,7 @@ const doGet = async (url, params, headers) => {
417417
try {
418418
const response = await fetch(`${url}?` + new URLSearchParams(params), {method: 'GET', headers});
419419
if (!response.ok) {
420+
//console.log(await response.json());
420421
throw new Error('Request failed with code ' + response.status)
421422
}
422423
return response.json();

sample-server/sample.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
API_URL=https://demo-api.incodesmile.com
2+
API_KEY=you-api-key
3+
FLOW_ID=Flow or Workflow Id from your Incode dashboard.
4+
ADMIN_TOKEN=Needed for the webhooks to be able to fetch Scores and auto-approve

0 commit comments

Comments
 (0)