EasyPost / easypost-csharp

EasyPost Shipping API Client Library for .NET and .NET Framework applications
https://easypost.com/docs/api
MIT License
66 stars 74 forks source link

[fix] Handle serializing array/list parameters in GET/DELETE query strings #601

Closed nwithan8 closed 3 weeks ago

nwithan8 commented 3 weeks ago

Description

Using the new tracking_codes parameter for the Tracker.Allparameter set was not serializing parameters properly, resulting in the value (a list of tracking codes) being lost in transit.

This PR introduces a fix in the query parameter construction process that will account for arrays. Specifically, the following list of tracking codes "001", "002", "003" will result in the following URL + query string being sent to the API: https://api.easypost.com/v2/trackers?tracking_codes[]=001&tracking_codes[]=002&tracking_codes[]=003. This is the format expected by our backend for proper parsing.

Accomplishing this requires some string manipulation in the query building process, as this is not the typical way the built-in System.Uri in .NET handles query arrays (typically would use comma-separated lists instead, producing https://api.easypost.com/v2/trackers?tracking_codes=001,002,003, which is incompatible with the API server).

tracking_codes is currently the only query-based parameter (GET/DELETE request) that is an array, so this issue did not arise until it was recently introduced.

Testing

Pull Request Type

Please select the option(s) that are relevant to this PR.