Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
WooCommerce API put from MySQL database in NodeJS

I have Beginner/entry-level knowledge so I am open to correcting my way of doing this.

I am trying to update my variation stock on Woocommerce using their RestAPI in NodeJS using the @woocommerce NPM I have the auth for WC and MySQL setup and need to query 4 columns in my wc_variations table

  1. vari_wp_id (The id of the specific variation)
  2. wp_id (it is a foreign key pulling the parten product ID from wc_products table)
  3. in_stock (1 or 2 for yes or no)
  4. stock (what I primarily need updating.)

I try to query the table and creating the variable data that I need (A lot of guides and tutorials use const so it is a little confusing switching. Same with what newer and more secure like I have seen Let be used in these situations?) The MySQL NPM example is similar but it includes an extra function and a [0].solution after result in console.log, not sure if that helps here.

I was also not sure how to split up my variables from the query since they will be doing different jobs later.

connection.query('SELECT * FROM wc_variations', function(err,result) {
   if (err) throw err;
   console.log(result);
});
  var prodid = {
     wp_id: 'wp_id', 
     vari_wp_id: 'vari_wp_id'
   };
  var inventory = {
     stock_status: 'stock_status',
     stock: 'stock'
   };

Here is my attempt at creating the put (from the @woo NPM). The URL requires 2 variables :wp_id and :vari_wp_id that I want to be pulled from the table (multiple vari_wp_id rows have the same wp_id since it is its parent product) Unsure If I have added this correctly. And then I included the inventory group as the data field.

    api.put("products/:wp_id/variations/:vari_wp_id", inventory)
  .then((response) => {
    // Successful request
    console.log("Response Status:", response.status);
    console.log("Response Headers:", response.headers);
    console.log("Response Data:", response.data);
    })
  .catch((error) => {
    // Invalid request, for 4xx and 5xx statuses
    console.log("Response Status:", error.response.status);
    console.log("Response Headers:", error.response.headers);
    console.log("Response Data:", error.response.data);
    })
  .finally(() => {
    // Always executed.
    });

This is the concoction I have created from different smaller projects I have created and am looking for ways to connect them all.

Is there an easier way or resource to learn up-to-date ways to implement variables?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda