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

[Feat]: Create Scan Form by List of Shipment Id's instead of list of full shipments #595

Closed chadwixk closed 3 weeks ago

chadwixk commented 1 month ago

Feature Request Is New

Description of the feature

We store the Shipment Id with the parcel (carton) created in our system. Later the user wants to create a Scan Form when the carrier arrives for a pick up of those parcels, which could count into 100 - 200. The current methods of creating a scan form in the library are to pass a list of Shipments (or to first create a batch, which also requires a list of shipments).

As a result, we need to loop through 100 - 200 parcels, get the shipment Id, then call the EasyPost API for each to retrieve the shipment. Then finally we can pass that list of shipments to the ScanForm.Create api call. This creates a lot of extra time and server calls/load on the EasyPost server.

Hence, asking for an EasyPost api call for ScanForm.Create that takes just a list of Shipment Ids instead of the full Shipment object.

nwithan8 commented 1 month ago

Hello, thanks for reaching out!

This is already possible, as you can construct local Shipment objects with IDs (which is ultimately the only property of a Shipment needed when dealing with an existing record for the API).

var client = new EasyPost.Client(new EasyPost.ClientConfiguration("my-api-key"));

EasyPost.Parameters.ScanForm.Create parameters = new()
{
    Shipments = new List<EasyPost.Parameters.IShipmentParameter>
    {
        new EasyPost.Models.API.Shipment
        {
            Id = "my-shipment-id"
        },
        new EasyPost.Models.API.Shipment
        {
            Id = "my-other-shipment-id"
        }
    }
};

EasyPost.Models.API.ScanForm scanForm = await client.ScanForm.Create(parameters);

This same concept applies to the majority of EasyPost objects, which can be constructed locally as well as retrieved via API calls, so long as the locally-constructed object mirrors an existing server-side record.