Get your API key and send your first Buybase API request!
Grab your API key
Go to the Buybase Developer Dashboard and grab your API key.
Create a Profile
const axios = require('axios'); async function createProfile() { const response = await axios.post('https://api.buybase.ai/profiles/create', {}, { headers: { 'Authorization': `Bearer ${process.env.BUYBASE_API_KEY}`, 'Content-Type': 'application/json', }, }); console.log('Profile ID:', response.data.profile.id); return response.data.profile.id; } // Usage createProfile().catch(console.error);
Add Style Preferences
async function createStyleProfile(profileId, styleDescription) { const response = await axios.post('https://api.buybase.ai/styles/create', { profile_id: profileId, text: styleDescription, }, { headers: { 'Authorization': `Bearer ${process.env.BUYBASE_API_KEY}`, 'Content-Type': 'application/json', }, }); console.log('Style ID:', response.data.style.id); return response.data.style.id; } // Usage createStyleProfile('prof_12345', 'Minimalist casual, neutral colors').catch(console.error);
Add Shipping Details
async function createShippingAddress(profileId, shippingDetails) { const response = await axios.post('https://api.buybase.ai/shipping/create', { profile_id: profileId, shipping_address: shippingDetails, }, { headers: { 'Authorization': `Bearer ${process.env.BUYBASE_API_KEY}`, 'Content-Type': 'application/json', }, }); console.log('Shipping ID:', response.data.shipping.id); return response.data.shipping.id; } // Usage createShippingAddress('prof_12345', { first_name: 'John', last_name: 'Doe', email: 'john.doe@example.com', phone: '+1234567890', address_1: '123 Main St', address_2: 'Apt 4B', city: 'San Francisco', country_code: 'US', province_code: 'CA', postal_code: '94105', }).catch(console.error);
Search for Products with Profile
async function searchProducts(profileId, query) { const response = await axios.post('https://api.buybase.ai/search/products', { profile_id: profileId, query: { text: query }, query_weight: 0.7, style_weight: 0.3, similarity_threshold: 0.25, result_count: 2, }, { headers: { 'Authorization': `Bearer ${process.env.BUYBASE_API_KEY}`, 'Content-Type': 'application/json', }, }); response.data.results.forEach(product => { console.log(`${product.title}: $${product.variants[0].price}`); console.log(`Checkout URL: ${product.variants[0].checkout_url_with_shipping}`); }); } // Usage searchProducts('prof_12345', 'Comfortable city walking shoes').catch(console.error);