How would I be able to send over information from my database?

Hi, I am currently working on a project which involves teaching people how to code with basic python. I am trying to generate questions automatically with the openai api. While I have set up the basic api and am able to communicate with the api. I want to be able to send over certain collections from my database as a JSON, so questions can be generated with higher relevancy and can be structured in the format I need them in. I am struggling with finding a way to do this. Is this possible? If not how else could I feed the api previous questions? For reference, I have currently made a call to get the database information I need. I have a message in messages that outlines what I want to be done and what the database information needs. I just need a way to pass the information through. Thank you!

Though it would be useful to share this as well. Here I have sent over questionp and questionMc too, only thing is i don;t know how to actually use that for the API input.

 const generateQuestion = async () => {
    const response = await fetch('/api/gpt4', {
        method: 'POST',
        headers: {
        'Content-Type': 'application/json'
        },
        body: JSON.stringify(
            {
                context : [{
                    "role": "user",
                    "content": "{I put what i want to be done in here}"
                    }],
                questionp : questionp,
                questionMc : questionMc
            }
        )
        });
      
        const data = await response.json();
        console.log(data);
      }
import { NextApiRequest, NextApiResponse } from 'next'

export default async function generateQuestions(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const messages  = req.body.context
  const apiKey = process.env.OPENAI_API_KEY
  const url = 'https://api.openai.com/v1/chat/completions'

  const body = JSON.stringify({
    messages,
    model: 'gpt-3.5-turbo',
    stream: false,
  })

  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${apiKey}`,
      },
      body,
    })
    const data = await response.json()
    res.status(200).json({ data })
  } catch (error : any) {
    res.status(500).json({ error: error.message })
  }
}