diff --git a/index.mjs b/index.mjs index 5513eee..e42f229 100644 --- a/index.mjs +++ b/index.mjs @@ -187,16 +187,26 @@ export default class WooCommerceRestApi { _request(method, endpoint, data, params = {}) { const url = this._getUrl(endpoint, params); + const headers = { + Accept: "application/json" + }; + // only set "User-Agent" in node environment + // the checking method is identical to upstream axios + if ( + typeof process !== "undefined" && + Object.prototype.toString.call(process) === "[object process]" + ) { + headers["User-Agent"] = + "WooCommerce REST API - JS Client/" + this.classVersion; + } + let options = { url: url, method: method, responseEncoding: this.encoding, timeout: this.timeout, responseType: "json", - headers: { - "User-Agent": "WooCommerce REST API - JS Client/" + this.classVersion, - Accept: "application/json" - } + headers }; if (this.isHttps) {