Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add example
  • Loading branch information
Alexandra Anghel committed Feb 9, 2022
commit a1dfb13a2d92b0fffb66c16292d130c490abd853
34 changes: 34 additions & 0 deletions playground/javascript/predict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { predictApi, ApiError } from '@algolia/predict';
import dotenv from 'dotenv';

dotenv.config({ path: '../.env' });

const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****';
const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****';

const userId = process.env.USER_ID || 'user1';

// Init client with appId and apiKey
const predictClient = predictApi(appId, apiKey);

async function testPredict() {
try {
const userProfile = await predictClient.fetchUserProfile({
userId: 'user1',
params: {
modelsToRetrieve: ["funnel_stage", "order_value", "affinities"],
typesToRetrieve: ["properties", "segments"],
},
});

console.log(`[OK]`, userProfile);
} catch (e) {
if (e instanceof ApiError) {
return console.log(`[${e.status}] ${e.message}`, e.stackTrace);
}

console.log('[ERROR]', e);
}
}

testPredict();