janssenr / SendCloudApi.Net

A C#/.net wrapper for the SendCloud API
MIT License
6 stars 5 forks source link

Bug in reading ParcelItems properties #14

Closed davidkdb closed 2 years ago

davidkdb commented 2 years ago

Hi,

We have a major problem when getting the shipment from Sendcloud.

The json payload is correct, but this case is quite special.

We actually have multi level properties, and it only allows for key and a value.

This is the payload from Sendcloud:

{ "next": null, "previous": null, "results": [{ "address": Mystreet", "address_2": "", "allowed_shipping_methods": [1883, 2021, 1951, 3486, 91, 3744, 3745, 2830, 89, 193, 3480, 111, 85, 78, 3808, 3807, 3806, 3805, 176, 250, 216, 127, 122, 316, 8], "barcode": "PS0000000171863582", "city": "MyCity", "company_name": "", "country": "DE", "created_at": "2021-10-27T09:15:12.490785Z", "currency": "EUR", "customs_invoice_nr": "#1033", "customs_shipment_type": 2, "email": "me@hotmail.com", "external_order_id": "4189342302402", "external_shipment_id": "", "house_number": "1", "integration": 123456, "name": "Me", "order_number": "#1033", "order_status": { "id": "unfulfilled", "message": "Unfulfilled" }, "parcel_items": [{ "description": "Product1", "hs_code": "", "origin_country": "", "product_id": "6109169156290", "properties": { "_upsell_discount_percent": 0.25, "_upsell_discount_label": "Angebot" }, "quantity": 1, "sku": "LG1311tt", "value": "18.00", "weight": "0.150" }, { "description": "Product2", "hs_code": "", "origin_country": "", "product_id": "6109173219522", "properties": { "1. Mini Lipstick": "Royal Red", "2. Mini Lipstick": "Rosy Pink", "3. Mini Lipstick": "Rusty Red", "_MemberCustomAttributes": [{ "Qty": 1, "SKU": "Mini-LS-26", "Name": "Mini Lipstick - Royal Red", "Barcode": "4260645340367", "variantGid": "gid://shopify/ProductVariant/123434434" }, { "Qty": 1, "SKU": "Mini-LS-25", "Name": "Mini Lipstick - Rosy Pink", "Barcode": "4260645340350", "variantGid": "gid://shopify/ProductVariant/3213331233" }, { "Qty": 1, "SKU": "Mini-LS-22", "Name": "Mini Lipstick - Rusty Red", "Barcode": "4260645340329", "variantGid": "gid://shopify/ProductVariant/43244344" }] }, "quantity": 1, "sku": "SET-018", "value": "32.00", "weight": "0.300" }], "payment_status": { "id": "paid", "message": "Paid" }, "postal_code": "1400", "sender_address": 111923, "shipment_uuid": "66efad62-2807-4dc8-bf62-6a2441acef0b", "shipping_method": 2830, "shipping_method_checkout_name": "Standard", "telephone": "", "to_post_number": "", "to_service_point": null, "to_state": null, "total_order_value": "54.99", "updated_at": "2021-10-27T09:15:12.490790Z", "weight": "0.450", "width": null, "height": null, "length": null }] }

So it fails when it tries to parse the _MemberCustomAttributes because there is an array and not a single value. In our case we could not care less about these properties, but it fails when we trying to get the shipment.

davidkdb commented 2 years ago

I was testing with setting the properties definition to Dictionary<string,object> and that seems to avoid the error message. It will work as normal on the single properties, and on the special one the Value will be object.

janssenr commented 2 years ago

Changed ParcelItem.Properties to Dictionary<string, object>