Skip to main content

snippets_js

Integration

New integration from credential
const algolia = yepcode.integration.algolia('credential-slug')
New integration from plain authentication data
const algoliasearch = require('algoliasearch');
const algolia = algoliasearch('your-application-id', 'your-write-api-key');

Search Index

Search index
const index = algolia.initIndex('your-index-name');
index.search('your query string').then(({ hits }) => {
console.log(hits);
});

Save Objects

Save objects
const index = algolia.initIndex('your-index-name');

const objects = [{
firstname: 'Jimmie',
lastname: 'Barninger',
objectID: 'myID1'
}, {
firstname: 'Warren',
lastname: 'Speach',
objectID: 'myID2'
}];

index.saveObjects(objects).then(({ objectIDs }) => {
console.log(objectIDs);
});

Save Single Object

Save single object
const index = algolia.initIndex('your-index-name');

index.saveObject({
firstname: 'Jimmie',
lastname: 'Barninger',
objectID: 'myID1'
}).then(({ objectID }) => {
console.log(objectID);
});

Delete Objects

Delete objects
const index = algolia.initIndex('your-index-name');
index.deleteObjects(['myID1', 'myID2']).then(({ objectIDs }) => {
console.log(objectIDs);
});