I have been developing a plugin, and I have been using the import-content plugin as a way to figure out how the Strapi system works.
My aim is to use the google sheets api to both create and update data. I have set up a endpoint for the plugin that receives a POST request with the ID of the google sheet.
There is a lot going on inside this function. And I have been trying to end the process with
ctx.send({message: 'ok'})
However, I keep getting an error message both in the browser and console. The weird part is that all my code is executed and the new content is created in the database. What is going on here?
My actual code includes oauth for the google sheets api - reads a json file then calls the api, processes the data, etc.
There is a lot of callbacks - do you think trying to flatten things out to with async would help?
Update
Flattening out callbackville worked somewhat. As long as the token is valid it returns 200. My only issue is the authorization.
Right now if the token is missing or not valid, I am outputting a url to the terminal. I then click that url, go through the google oauth, and get redirected back to the admin homepage. I then copy and paste the code url param from the browser back into the terminal - this triggers the token to be saved to a json file. This can’t be the best way to do this…are we able to make our own route handlers?
Could be a cool plugin, it writes the ID back to the google sheet so it can be used for updates later…ecommerce
That means some of your functions return something that causes 404. I would write all that custom login into a custom service with try-catch instead of writing all the logic in the controller.
Its mostly Koa, if you want to gather a fairly strong knowledge of Strapi; understanding some of the tech we use like Koa (and its many packages), Bookshelf/Knex, Mongoose, etc is a great place to start.