Quick Start
This guide demonstrates how to integrate and utilize the powerful Odyssey API to create a dynamic and interactive chat application. With this example, you'll learn how to fetch and post data using the Odyssey API in a Next.js environment, making it easier to build robust applications.
Getting an API Key
tip
Your Odyssey backend instance needs to be built before you can use the API. Please wait for a confirmation email after completing the build process.
1. Open team settings and select the team
2. Go to API Keys tab
3. Click “Create API Key” button
4. Open team settings and seEnter key name and click “Create API Key” button
Example API Calls
Get Team Members
export default async function handler(req, res) {
const { slug } = req.query;
const response = await fetch(
`${process.env.API_ENDPOINT}/api/teams/${slug}/members`,
{
headers: {
"x-api-key": process.env.API_KEY,
},
}
);
if (response.ok) {
const data = await response.json();
return res.status(200).json(data);
}
return res.status(response.status).json({ message: response.statusText });
}
Get Workspace ID
export default async function handler(req, res) {
const { userid } = req.headers;
const response = await fetch(
`${process.env.API_ENDPOINT}/api/build-status`,
{
headers: {
"x-api-key": process.env.API_KEY,
userId: userid,
},
}
);
if (response.ok) {
const data = await response.json();
return res.status(200).json(data);
}
console.log(response)
return res.status(response.status).json({ message: response.statusText });
}
Get Conversations
export default async function handler(req, res) {
const { workspaceId } = req.query;
const { userid } = req.headers;
const response = await fetch(
`${process.env.API_ENDPOINT}/api/conversations?workspaceId=${workspaceId}`,
{
headers: {
"x-api-key": process.env.API_KEY,
userId: userid,
},
}
);
if (response.ok) {
const data = await response.json();
return res.status(200).json(data);
}
return res.status(response.status).json({ message: response.statusText });
}
Get messages
export default async function handler(req, res) {
const { workspaceId, conversationId } = req.query;
const { userid } = req.headers;
const response = await fetch(
`${process.env.API_ENDPOINT}/api/chat/messages?workspaceId=${workspaceId}&conversationId=${conversationId}`,
{
headers: {
"x-api-key": process.env.API_KEY,
userId: userid,
},
}
);
if (response.ok) {
const data = await response.json();
return res.status(200).json(data);
}
return res.status(response.status).json({ message: response.statusText });
}
Send message
export default async function handler(req, res) {
const { workspaceId, conversationId, message } = req.body;
const { userid } = req.headers;
const response = await fetch(
`${process.env.API_ENDPOINT}/api/chat/message`,
{
method: 'POST',
headers: {
"x-api-key": process.env.API_KEY,
userId: userid,
'Content-Type': 'application/json',
},
body: JSON.stringify({
workspaceId,
conversationId,
message
}),
}
);
if (response.ok) {
const data = await response.json();
return res.status(200).json(data);
}
return res.status(500).json({ message: "Internal server error" });
}
Usefull links
- Odyssey AI - use Odyssey AI App