How to fetch data from an external API to populate the data entry in Strapi Admin portal?

Hi aleaff!

What you should probably do is to develop a custom route with a controller / service logic which you can read about in the Strapi docs in the Development / Back-end customization segment (Back-end customization - Strapi Developer Docs).

You should probably use fetch API to GET your data into the Strapi server first (the best way is to either do it in a controller within custom API so that you can start it on a request with use of a webhook as needed OR… to have a CRON scheduled for you to do that on a time-interval basis) and then populate the database with it by using the Entity Service API create method (CRUD operations with Entity Service API - Strapi Developer Docs) in a loop for all the data (should probably come as an array of objects) that will rather need to be mapped in a proper way before you do that so that it matches the strapi collection structure.

Here’s the code snippet for the Entity service method mentioned:

const entry = await strapi.entityService.create('api::article.article', {
  data: {
    title: 'My Article',
  },
});
 

Also if you decide to use a webhook to trigger the fetch request and then creating the entries in your database you will also might want to use a service to separate that logic so that your code stays DRY if you’ll need to reimplement it.

Hope that helps and if anything is not clear enough at this point and you would like me to elaborate on how you can achieve it, please feel free to get back to me and I will try to give you a more comprehensive answer to this.

Best of luck,
Paul :slight_smile: