0

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.

2
  • It could be a caused by a theme/plugin, if you say your above implementation works on another site. Have you tried troubleshooting for plugin conflict? You can track down the plugins causing the conflict with help from your browser console or manually deactivating & reactivating each plugin, one by one guide. Also check for outdated plugins. Let us know about your findings. Commented Feb 5, 2024 at 15:40
  • 1
    @Richard Thanks for your reply, the plugins are the same on both sites, up to date, I tried disabling them, nothing new happend. Cleared the caching and checked the status of the site/Woocommerce, everything seems fine, no errors. If I'm unable to find the issue, I will use a plugin and import all the products with the updated data, that's the plan B :). Thanks again Commented Feb 6, 2024 at 9:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.