janssenr / SendCloudApi.Net

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

BulkCreate just for multicollo? #30

Open jpp-skynet opened 1 month ago

jpp-skynet commented 1 month ago

Tried to create 3 parcels of unrelated orders at once with BulkCreate, but just one was returned and created.

janssenr commented 1 month ago

Can you provide a code example? Then I will check tonight.

Op vr 12 jul. 2024 11:33 schreef jpp-skynet @.***>:

Tried to create 3 parcels of unrelated orders at once with BulkCreate, but just one was returned and created.

— Reply to this email directly, view it on GitHub https://github.com/janssenr/SendCloudApi.Net/issues/30, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXPBWMKWAJNR6R5SEZ2HALZL6PFDAVCNFSM6AAAAABKYSLOPCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQYDKMJVGQ2DQNY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jpp-skynet commented 1 month ago

I switched to singleParcel and they have errors (missing zipcode, weight too much,..),

The problem is that BulkCreate seems to hide them, or at least I cannot see them I am just getting a general Sendcloud Exception IIRC.

If BulkCreate should work for parcels from different orders I'll trust you.

Btw, do you have this implemented?

https://api.sendcloud.dev/docs/sendcloud-public-api/labels/operations/get-a-label-label-printer-1 Retrieve PDF label documents suitable for label printers for multiple different parcels at the same time.

I

janssenr commented 1 month ago

This code works. The response contains 2 parcels

var parcels = new[]
            {
                new CreateParcel
                {
                    Name = "John Doe",
                    CompanyName = "SendCloud",
                    Address = "Insulindelaan",
                    HouseNumber = "115",
                    City = "Eindhoven",
                    PostalCode = "5642CV",
                    Telephone = "+31612345678",
                    RequestLabel = true,
                    Email = "john@doe.com",
                    Country = "NL",
                    Shipment = new ShippingMethod { Id = 8 },
                    Weight = 10,
                    OrderNumber = "1234567890",
                    InsuredValue = 2000,
                    TotalOrderValue = "11.11",
                    TotalOrderValueCurrency = "EUR",
                    Quantity = 1
                },
                new CreateParcel
                {
                    Name = "John Doe",
                    CompanyName = "SendCloud",
                    Address = "Insulindelaan",
                    HouseNumber = "115",
                    City = "Eindhoven",
                    PostalCode = "5642CV",
                    Telephone = "+31612345678",
                    RequestLabel = true,
                    Email = "john@doe.nl",
                    Country = "NL",
                    Shipment = new ShippingMethod { Id = 8 },
                    Weight = 8,
                    OrderNumber = "1234567891",
                    InsuredValue = 500,
                    TotalOrderValue = "99.99",
                    TotalOrderValueCurrency = "EUR",
                    Quantity = 1
                }
            };
            var response = await _apiV2.Parcels.BulkCreate(parcels);

For the "Retrieve PDF label documents suitable for label printers for multiple different parcels at the same time.", you can use this code:

            var url = "https://panel.sendcloud.sc/api/v2/labels/label_printer?ids=395012198,395012199";
            var label = await _apiV2.Label.Download(url);
            File.WriteAllBytes(@"C:\Temp\SendCloud_Retrieve_a_PDF_label_for_a_label_printer.pdf", label);