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

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I am a newbie to Strapi v4 and I know how to create a data entry within the Strapi Admin dashboard for a collection type. What I would like to do is to fetch the data from an external API and use the fetched data to populate the data entry. Is it possible? If yes, would you be kind enough to show me how step-by-step?

So far the only example I can found in the Strapi v4 document is dealing with the docker file.

For example, I have a Java API that provides all the necessary data, and I want to do a GET/ from it. The returned data will be used to create the data entry for a collection type.

Thank you.

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:

Thank you for your help. I will give it a try.

Hi paulstone,

I believe I understand the concept, but it is the “how to” that gets me because the lack of domain knowledge in Strapi. My background is in .NET Core and I am relative new to CMS. If you can assist me with more details for the “how to” between the external API to Strapi that would be great. Once the data is in Strapi, I know what to do.

Thank you.

Working example

async getUser(ctx) {

      // get parameter from URL
      const { id } = ctx.params;
      // external API
      const url = `${EXTERNAL_API_URL}/${id}`;
      // fetch data from external API
      const { data } = await axios.get(url);
      ctx.body = data;

      // Use strapi.entityService to create a new data entry in Strapi
      await strapi.entityService.create("api::end-user.end-user", {
        data: data,

      return ctx.body;

@aleaff could you please specify where to put this code in the repo? Any additional changes in controllers or routes are needed?