admesh-nodejs
v1.0.0
Published
Simple Node.js SDK for AdMesh API - Get personalized recommendations
Maintainers
Readme
AdMesh Node.js SDK
A simple Node.js SDK for integrating with the AdMesh API to get personalized recommendations for your applications.
Installation
npm install admesh-nodejsGetting Started
- Sign up for an AdMesh account at https://dashboard.useadmesh.com
- Get your API key from the dashboard
- Start making recommendations!
Quick Start
const AdMeshClient = require('admesh-nodejs');
// Initialize the client with your API key
const client = new AdMeshClient('your-api-key-here');
// Get recommendations
async function getRecommendations() {
try {
const recommendations = await client.getRecommendations('best laptops for programming');
console.log(recommendations);
} catch (error) {
console.error('Error:', error.message);
}
}
getRecommendations();API Reference
Constructor
const client = new AdMeshClient(apiKey, options);Parameters:
apiKey(string, required): Your AdMesh API keyoptions(object, optional): Configuration optionsbaseURL(string): API base URL (default: 'https://api.useadmesh.com')timeout(number): Request timeout in milliseconds (default: 10000)
Methods
getRecommendations(query, options)
Get personalized recommendations based on a search query.
Parameters:
query(string, required): The search queryoptions(object, optional):agentId(string): Specific agent ID to uselimit(number): Number of recommendations to return (default: 5)filters(object): Additional filters to apply
Returns: Promise that resolves to recommendations data
Example:
const recommendations = await client.getRecommendations('best smartphones', {
agentId: 'agent-123',
limit: 10,
filters: {
category: 'electronics',
priceRange: 'mid'
}
});testConnection()
Test the API connection.
Returns: Promise that resolves to boolean (true if successful)
Example:
const isConnected = await client.testConnection();
if (isConnected) {
console.log('API connection successful');
} else {
console.log('API connection failed');
}Error Handling
The SDK throws descriptive errors that you can catch and handle:
try {
const recommendations = await client.getRecommendations('query');
} catch (error) {
console.error('Error:', error.message);
console.error('Status:', error.status); // HTTP status code if available
console.error('Data:', error.data); // Response data if available
}Environment Variables
You can set your API key as an environment variable:
export ADMESH_API_KEY=your-api-key-hereThen use it in your code:
const client = new AdMeshClient(process.env.ADMESH_API_KEY);License
MIT
