Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrations.GetShipments() errors #31

Open
jpp-skynet opened this issue Jul 16, 2024 · 5 comments
Open

Integrations.GetShipments() errors #31

jpp-skynet opened this issue Jul 16, 2024 · 5 comments

Comments

@jpp-skynet
Copy link

Sorry to bother you again ;(

Shipment[] pTest= await SendcloudClient.Integrations.GetShipments(366789, orderNumber: "405-0794075-2815560");
pTest= await SendcloudClient.Integrations.GetShipments(366789, shippingRules: true);

First line works, but second doesn't. Using other filters like startDate also return the same error:
System.Runtime.Serialization.SerializationException

"Expected 'Element'.. 'Text' was found with name '',namespace ''. " (translated, it comes in my pc language)

Maybe they changed the returned element?

@janssenr
Copy link
Owner

I cannot replicate the error. When I use shippingRules: true, i do not get an error.
Which integration do you use?
Or is it possible you sent me your credentials for SendCloud?

@jpp-skynet
Copy link
Author

jpp-skynet commented Jul 16, 2024

I'm doing more tests, it seems to be related with the amount of shipments involved

pTest= await Global.SendcloudClient.Integrations.GetShipments(366789, shippingRules: true, startDate: DateTime.Today.AddDays(0)); //39 elem ok
pTest= await Global.SendcloudClient.Integrations.GetShipments(366789, shippingRules: true, startDate: DateTime.Today.AddDays(-1)); //Exception

What XML library are you using? Could you try invoking GetShipments with +100 shipments returned?

Btw I'm using verbose: true when creating new SendCloudApi.Net.V2.SendCloudApi(...)

@jpp-skynet
Copy link
Author

jpp-skynet commented Jul 16, 2024

"next": "https://panel.sendcloud.sc/api/v2/integrations/366789/shipments?cursor=cD0yMDI0LTA3LTE1KzE5JTNBNTIlM0EzMyUyQjAwJTNBMDA%3D&start_date=2024-07-13",
"previous": null,

It returns 50 per page, is the cursor thing working in this project v2?

@janssenr
Copy link
Owner

I only have the API integration. So I cannot test this with my own account.

@jpp-skynet
Copy link
Author

jpp-skynet commented Jul 18, 2024

I don't understand, next/previous is part of the API endpoint

https://api.sendcloud.dev/docs/sendcloud-public-api/integrations/operations/list-integration-shipments

I wrote my own API call and it's working:

    public static async Task<Shipment[]> GetShipsSendCloudAsyncFixed(int mpId, DateTime startDate)
    {
        List<Shipment> res = null;

        using (var client = new System.Net.Http.HttpClient())
        {
            string token = $"Basic {Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(SendCloudApiPublic + ":" + SendCloudApiPrivate))}";
            client.DefaultRequestHeaders.Add("Authorization", token);

            string since = startDate.ToString("yyyy-MM-dd");
            string url = "https://panel.sendcloud.sc/api/v2/integrations/" + mpId + "/shipments?start_date=" + since + "&shipping_rules=true";

            //50 items by page
            while (url != null)
            {
                var resp = await client.GetAsync(url);

                if (resp.IsSuccessStatusCode)
                {
                    var jsonResult = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (res == null)
                        res = new List<Shipment>();
                    var model = JsonConvert.DeserializeObject<Wrapper>(jsonResult);
                    res.AddRange(model.results);
                    url = model.next;
                }
            }

            return res.ToArray();
        }
    }
    public class Wrapper
    {
        public string next { get; set; }
        public string previous { get; set; }
        public SendCloudApi.Net.V2.Models.Shipment[] results { get; set; }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants