I am building an embedded app to select products and save them to a database. I want to make a POST request to an endpoint that will save my selections to a mongodb database.
I used the Shopify CLI to create a Node.js application. My attempts to create a working API endpoint so far have entailed:
- Create pages/api/index.js file that exports a function to respond to GET and POST requests.
- Add a Polaris Button component to pages/index.js along with a handler function to make an axios request to the api.
- Add route.get(‘/api’) and route.post(‘api’) routes in server.js
At this point, I get a 500 server error with a message:
Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.> in testPost (at _app.js:30)
_app.js line 30 is inside the ApolloProvider, so I think somehow I need to separate the API response. But I’m lost at from here. Any suggestions on how I can create a working API endpoint for POST requests from my embedded app?
Thank you!!