Database Example

Learn how to store and manage user data with the BlueNexus database

Here's a full end-to-end example of storing and retreiving user data:

import fetch from "node-fetch";

// CREATE RECORD
const memoryData = {
  title: "Morning Workout",
  content: "Completed 30-minute run in the park. Feeling energized!",
  category: "fitness",
  timestamp: "2024-12-15T08:30:00Z",
  tags: ["exercise", "health", "running"],
  mood: "energized",
  schemaUri: "https://example.com/schemas/memory.json", // Optional (see structured data)
};

const response = await fetch(
  "https://api.bluenexus.ai/api/v1/data/memories",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${USER_ACCESS_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(memoryData),
  }
);

const createdRecord = await response.json();

// Example response:
// {
//   "id": "66bd3762c23f9e3f152fb4d1",
//   "title": "Morning Workout",
//   "content": "Completed 30-minute run in the park. Feeling energized!",
//   "category": "fitness",
//   "timestamp": "2024-12-15T08:30:00Z",
//   "tags": ["exercise", "health", "running"],
//   "mood": "energized",
//   "createdAt": "2024-12-15T09:00:00.000Z",
//   "updatedAt": "2024-12-15T09:00:00.000Z"
// }

// GET RECORD
const recordId = "66bd3762c23f9e3f152fb4d1";

const response = await fetch(
  `https://api.bluenexus.ai/api/v1/data/memories/${recordId}`,
  {
    headers: {
      Authorization: `Bearer ${USER_ACCESS_TOKEN}`,
    },
  }
);

const record = await response.json();

// Example response:
// {
//   "id": "66bd3762c23f9e3f152fb4d1",
//   "title": "Morning Workout",
//   "content": "Completed 30-minute run in the park. Feeling energized!",
//   "category": "fitness",
//   "tags": ["exercise", "health", "running"],
//   "createdAt": "2024-12-15T09:00:00.000Z",
//   "updatedAt": "2024-12-15T09:00:00.000Z"
// }

// DELETE RECORD
const response = await fetch(
  `https://api.bluenexus.ai/api/v1/data/memories/${recordId}`,
  {
    method: "DELETE",
    headers: {
      Authorization: `Bearer ${USER_ACCESS_TOKEN}`,
    },
  }
);

// Returns HTTP 204 No Content on success

Last updated