-
Hi All, I am trying to utilize the WordPress REST API with Basic Auth using application password: var wp_api = new WooCommerceNET.RestAPI("https://my-site/wp-json/wp/v2/", "admin", "xxxx xxxx xxxx xxxx xxxx xxxx");
wp_api.Debug = true;
var wp_client = new WooCommerce.NET.WordPress.v2.WPObject(wp_api);
var result = wp_client.Categories.GetAll().GetAwaiter().GetResult(); // Error occurs here And receiving the following error:
However the WC REST API works as expected: var wc_api = new WooCommerceNET.RestAPI("https://my-site/wp-json/wc/v3/", "admin", "xxxx xxxx xxxx xxxx xxxx xxxx");
wc_api.Debug = true;
var wc_client = new WooCommerceNET.WooCommerce.v3.WCObject(wc_api);
var result = wc_client.Product.GetAll().GetAwaiter().GetResult(); // Works fine here Does anyone know what is wrong here? Is there anything needs to be configured? |
Beta Was this translation helpful? Give feedback.
Answered by
fairking
Oct 5, 2024
Replies: 1 comment 1 reply
-
Ok, looks like something broken in the WooCommerce.NET API Client itself. My fix was to set the version to V3 as a workaround: var wp_api = new WooCommerceNET.RestAPI("https://my-site/wp-json/wp/v2/", "admin", "xxxx xxxx xxxx xxxx xxxx xxxx");
// Fix the version number, so we can still use Basic Authentication in Wordpress API
wp_api.GetType()
.GetProperty(nameof(wp_api.Version), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(wp_api, WooCommerceNET.APIVersion.Version3); After that the API started working as expected. Thanks guys for the package 👍 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fairking
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, looks like something broken in the WooCommerce.NET API Client itself.
My fix was to set the version to V3 as a workaround:
After that the API started working as expected. Thanks guys for the package 👍