How submit data from react to backend node js in Shopify using fetch or any other way ?

How submit data from react to backend node js in Shopify using fetch or any other way ?

Girish_Rajwani
Shopify Partner
82 3 8

Hi Guys,

 

how to submit data from react to backend node js in Shopify using fetch or any other way ?

 

i am using useAuthenticatedFetch which not working as POST for submitting data , giving error No shop provided.

Moreover it is working as GET. 

 

is there any solution or other option for submitting data ? 

 

Thanks in advance 🙂

 

Girish | Shopify Expert  
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - My Shopify Apps: App Store | Looking for a solution to a problem in your store? Send me an email

Reply 1 (1)

oscprofessional
Shopify Partner
15950 2385 3094

Hi @Girish_Rajwani,

To submit data from React you can use the Fetch API or make http POST request to backend using Fetch API.

Example : 

import { connection } from "/folder/filename.js"   // DB connection file path
const express = require('express');
const app = express();

app.use(express.json());

app.post('/api/submit-data', (req, res) => {
  const data = req.body.data;
    function(data){
          connection.query(`INSERT Statement');   // For example your insert statement
          // You can perform any necessary operations here (e.g., save the data to a database)
   }
  // Returns response
  res.json({ message: 'Data submitted successfully' });
});

'/api/submit-data' is the endpoint which is the route in your Node.js backend server which will handle data for submission.

Code : 

import { connection } from "/folder/filename.js"   // DB connection file path
const express = require('express');
const app = express();

app.use(express.json());

app.post('/api/submit-data', (req, res) => {
  const data = req.body.data;
    function(data){
          connection.query(`INSERT Statement');   // For example your insert statement
          // You can perform any necessary operations here (e.g., save the data to a database)
   }
  // Returns response
  res.json({ message: 'Data submitted successfully' });
});

// Start the server
app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

 

Hope this might be helpful for you.

Thanks...

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free