Quickstart
Get started with Buybase in minutes!
Introduction
In this quickstart guide, you’ll learn how to:
-
Create a new user for your Buybase app.
-
Search a Shopify store’s product catalog using natural language.
-
Automate the purchase of an item on behalf of your user.
Security Tip: To avoid exposing sensitive information, we recommend using a secure backend service to proxy all your API requests to Buybase.
Prerequisites
-
An
API KEY
from your OpenAI account. -
An
APP ID
,STORE ID
, andAPI KEY
from your Buybase account. -
A store setup with a product catalog and the Buybase Shopify app installed.
-
A NextJS project setup on your local machine.
Note: If you don’t have a Shopify store to test with, Buybase manages a
test store for your use. Store ID: 1234567890
Create a New User
To create a new Buybase user, you’ll need to make a request to the /users/create
endpoint.
We create users for your Buybase project so that we can track their purchasing history, and personalize the search experience for them in the future.
See the API Reference for more information.
Implementing in Sign Up Flow
We recommend creating a Buybase user when a user signs up for your application. This way, it’s done at the most relevant time in the user’s journey, and will save you and them extra steps down the line.
Frontend
On your frontend, you might have a component that handles the sign up flow, like <SignUp />
.
Let’s say the path to this component is app/components/SignUp.js
.
API Route
Let’s create a NextJS API route to create a Buybase user.
The path to the API route is app/your-api/buybase/users/create/route.js
.
Search a Shopify Store
Now that we have a Buybase user for our Buybase project, let’s move onto searching a Shopify store’s product catalog using natural language.
The Buybase search
endpoint is powerful, allowing you to get conversational and abstract about what you want to buy, and even include price filters to narrow down your search based on a budget.
See the API Reference for more information.
Setup a Search Tool
If our goal is to search for a product using natural language, we’re going to need an LLM to listen to what the user is saying, and then generate a query that describes what they’re requesting.
We can do this using OpenAI’s function calling capabilities by creating a tool which calls the Buybase /search
endpoint.
Read more about Function Calling in the OpenAI docs.
Tool Schema
Let’s define the schema for our search tool using JSON. This describes the parameters that the LLM will use to generate a response from the Buybase /search
endpoint.
Tool Implementation
OpenAI’s ecosystem supports tools for their Completions API
and their Assistants API
.
For this example, we’ll be using a chat completion function.
This would generate a response from the LLM that includes a function call to the search_tool
function.
Display Search Results
Since this is a conversational shopping experience, our frontend needs a way to display a log of the conversation history between the user and the assistant. When we receive a tool call, we’ll want to display the search results in the conversation history.
You might setup a <Conversation />
component that looks something like this:
Frontend
API Route
Let’s create a NextJS API route to handle the search request.
The path to the API route is app/your-api/buybase/search/route.js
.
Buy Products
With our conversation UI and search results display in place, let’s implement the purchasing functionality. The SearchResults.jsx component above provides the foundation - now we need to create a component that displays detailed product information and enables one-click purchasing.
Frontend
API Route
Let’s create a NextJS API route to handle the buy request.
The path to the API route is app/your-api/buybase/buy/route.js
.