XiaoFaye / WooCommerce.NET

A .NET Wrapper for WooCommerce/WordPress REST API
MIT License
391 stars 217 forks source link

Error on Deserializing object of Type Media #756

Closed marcschmidt1 closed 12 months ago

marcschmidt1 commented 1 year ago

Make sure you have included the below details when open an issue. Thank you.

static string trimstr(string json)
 {
     return json.Trim(new char[] { '\uFEFF', '\u200B' });
 }
 static void Main(string[] args)
 {
     RestAPI rest = new RestAPI("https://XXXXXXXde/wp-json/wc/v3/", "ck_a5578e4e38dXXXXXXXX9fe8fc1719d6511", "cs_42cb95b6f7a06e421399XXXXXXXXXX3556fd1a31");
     RestAPI WPrest = new RestAPI("https://mikeshp.de/wp-json/wp/v2/", "ck_a5578e4e38XXXXXXXXXXX92b99fe8fc1719d6511", "cs_42cb95b6f7a06eXXXXXXXXXXacb3556fd1a31", jsonDeserializeFilter: trimstr);
     wc = new WCObject(rest, CultureInfo.GetCultureInfo("de-DE"));
      wp = new WPObject(WPrest);

     string a = "Amrum.jpg";
     string b = @"C:\Temp\Amrum.jpg";
     Media m = CreateImageAsync(a, `b).Result;`

      private static async Task<Media> CreateImageAsync(string a, string b)
      {
          return await wp.Media.Add(a, b);
      }

-Error Message : "One or more errors occurred. (There was an error deserializing the object of type WooCommerce.NET.WordPress.v2.Media. Encountered unexpected character 'o'.)"

I get an error on add an Image via WP Rest Api I also read your article so i add the trim function, but it doesnt work for me. any ideas ?

Greetings

XiaoFaye commented 1 year ago

Set RestAPI.Debug flag to true, you should see details in the error message.

marcschmidt1 commented 12 months ago

@XiaoFaye thx for advise, helps a lot :)