-
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.
Replies: 2 comments 2 replies
-
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.
-
Because there is no v3 api for the WP (https://developer.wordpress.org/rest-api/reference/).
…________________________________
From: richardaubin ***@***.***>
Sent: Thursday, April 3, 2025 1:54 AM
To: XiaoFaye/WooCommerce.NET ***@***.***>
Cc: Den ***@***.***>; State change ***@***.***>
Subject: Re: [XiaoFaye/WooCommerce.NET] WordPress REST API Basic Authorization not working (Discussion #783)
Why are you not using the v3 api?
—
Reply to this email directly, view it on GitHub<#783 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADG62TZTDPRO76CHO5QJNKT2XSBFJAVCNFSM6AAAAABPNMQGJOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENZQG43DMNI>.
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
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 👍