In this quickstart guide, you’ll learn how to:

  1. Create a profile for your Buybase app.
  2. Add style preferences.
  3. Attach shipping details.
  4. Perform personalized product searches.
1

Grab your API key

Go to the Buybase Developer Dashboard and grab your API key.

2

Create a Profile

Profiles store user preferences and shipping details for personalized experiences.

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);
3

Add Style Preferences

Attach style preferences to enhance product recommendations.

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);
4

Add Shipping Details

Store shipping info to streamline checkout.

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);
5

Search for Products with Profile

Use natural language and personalization to search products.

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);

Explore more in the API Reference.