I have an issue with the WooCommerce Rest API, just to clarify, I've worked with the API multiple times on many sites, but I've never encountered this "error".
My issue is that the response data is coming back as a string, not in a basic Array format, but rather like this: '[{id:...}]...', I have tried deleting the strings from the first and last line, but the log still showed it as a string. The rest of the response is in JSON format, I even tried defining the content-type as application/json in the headers, I know it's a GET method but thought it might help, but it didn't. I tried different credentials for another site, the output was good there, so it must be a setting/plugin making it wrong or maybe using developer mode on the site? Anyway, I'd appreciate any help or tip :)
Thank you!
Snippet of the code:
`WooCommerce.get("products?lang=en&per_page=5&page=1", {
})
.then(async (response) =\> {
const products = await response.data;
console.log(products);
})
.catch((error) =\> {
console.error("Error fetching:", error);
});
part of the response:
\[Symbol(errored)\]: null,
\[Symbol(kHighWaterMark)\]: 16384,
\[Symbol(kRejectNonStandardBodyWrites)\]: false,
\[Symbol(kUniqueHeaders)\]: null
},
data: '\[{"id":15432,"name":"Item","slug":"item-classic"...`
I followed the instructions in the woocommerce API, but nothing, also I've never encountered something like this.