diff --git a/nodes/woocommerce-config.js b/nodes/woocommerce-config.js index 2b4382a..3f5f9ef 100644 --- a/nodes/woocommerce-config.js +++ b/nodes/woocommerce-config.js @@ -9,16 +9,25 @@ module.exports = function (RED) { const node = this; node.baseUrl = (config.baseUrl || "https://example.com/wp-json/wc/v3").replace(/\/+$/, ""); + // Credentials from node-RED credentials tab OR from config node fields node.consumerKey = (this.credentials && this.credentials.consumerKey) || config.consumerKey || ""; node.consumerSecret = (this.credentials && this.credentials.consumerSecret) || config.consumerSecret || ""; node.sendRequest = function (method, path, body, msgHeaders, callback) { const url = new URL(node.baseUrl + path); + + // Append consumer_key and consumer_secret as query parameters (proven working in curl) + if (node.consumerKey) { + url.searchParams.set('consumer_key', node.consumerKey); + } + if (node.consumerSecret) { + url.searchParams.set('consumer_secret', node.consumerSecret); + } + const parsedBody = body !== undefined ? (typeof body === "string" ? body : JSON.stringify(body)) : undefined; const headers = Object.assign({ "Accept": "application/json", "Content-Type": "application/json" }, msgHeaders || {}); if (parsedBody !== undefined) headers["Content-Length"] = Buffer.byteLength(parsedBody); - headers["Authorization"] = "Basic " + Buffer.from(node.consumerKey + ":" + node.consumerSecret).toString("base64"); const options = { method, hostname: url.hostname, @@ -54,4 +63,4 @@ module.exports = function (RED) { consumerSecret: { type: "password" } } }); -}; +}; \ No newline at end of file