Adjust API endpoint for inserting data

Hey everyone, i want to create API endpoint for insert data from theme to my database how i can implement this?

Can you share your usecase? From a functional perspective, the ask doesn’t make much sense :slight_smile:

Look i have on my theme part, i have search result which i want to save in my custom database fields i already created it, and i want to create api endpoint in which i can request to core and in core i can push the data into my database

// In the custom API endpoint file (ghost/core/server/api/endpoints/custom.js)
module.exports = {
  add: {
    permissions: true,
    query(frame) {
      // Extract the data from the request body
      const { myData } = frame.data;
      
      // Insert the data into the MySQL database
      return knex('my_table')
        .insert(myData)
        .then(() => {
          return { success: true };
        })
        .catch((err) => {
          return { success: false, error: err.message };
        });
    }
  }
};

this part of code i found on the internet

To be honest, in these use cases, my suggestion is to create a separate app if you’re trying to reuse the Ghost database (which I suggest you shouldn’t do). You can configure nginx to proxy requests for a certain route to your custom app instead of Ghost.

so the recommend is not go inside the core and do changes in it, am i right?

Yes, that’s correct!