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
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?