Proper way to insert data via Strapi from external script but on same server?

System Information
  • 3.2.4:
  • Ubuntu 18.04.4 LTS:
  • mysql:
  • v12.16.2:
  • 6.14.4:
  • 1.22.5:

Up to this point I’ve had success with using the Strapi API from the front-end vue nuxt client, using the $strapi variables that are available on the client, getting them authenticated, then using middleware to validate accessing the Strapi API. Then when needing to create a custom response, using the controllers for each collection which gives me access to the strapi variables via ctx.

What I need to do is enter information into the database for users, from another script, php, etc.that is running on the same server, and was wanting to know if there’s a way to do that which bypasses having to get authenticated as admin via the Strapi API using http. Just pass the data to a .js handler on the strapi server, and have it enter the information into the database. I wanted to avoid doing direct DB access so as not to conflict with Strapi’s management. If I had to create a custom javascript handler to do this, where do I put it, and when I run it and pass the arguments to it, how do I load the current Strapi server instance’s variables so I can interact with the running Strapi server?

Thanks! Rxrx

I would not recommend executing JS files manually. Since that’s a really bad practice.

A better approach to connect two different apps (as you mentioned, strapi and another PHP app) is to use REST API. Create an Admin role in Strapi which has access to update everything, generate a token for it and use it in your PHP code to make requests to the Strapi’s APIs.

Short answer: You can’t. You can’t achieve that in any node app.

1 Like