EasyPost API - print_custom_1选项不会在标签上打印

时间:2015-07-07 20:21:25

标签: c# easypost

这让我殴打了一个多小时。我是EasyPost的新手,我正在尝试在我的标签上放置一些自定义文本(在我的特定情况下,它是放在包中的SKU),但它似乎永远不会起作用。我正在使用easypost的官方nuget包,但我猜它是独立于平台的。

Shipment shipment = new Shipment() {
    to_address = toAddress,
    from_address = fromAddress,
    parcel = parcel
};

shipment.Create();
var lowestRate = shipment.LowestRate(includeServices: new List<string>() { "First" }, includeCarriers: new List<string>() { "USPS" });

shipment.Buy(lowestRate);

shipment.options.Add("print_custom_1", "this is some sample text");
shipment.options.Add("print_custom_2", "abc");
shipment.options.Add("print_custom_3", "xyz");

shipment.GenerateLabel("pdf");

1 个答案:

答案 0 :(得分:1)

嗯,这很烦人。当你退后一步时,它是有道理的。问题是需要将选项设置为 PRIOR 以创建货件。在我看来,它只是一个打印问题(它是),但有其他选项可以并且确实影响运输成本,这意味着在创建货件时需要设置选项。即使在创建之后但在“购买”之前设置选项也不起作用。

请参阅下面的工作代码:

Shipment shipment = new Shipment() {
    to_address = toAddress,
    from_address = fromAddress,
    parcel = parcel
};

//DO THIS BEFORE CREATING!
shipment.options = new Dictionary<string, object>();
shipment.options.Add("print_custom_1", "this is some sample text");
shipment.options.Add("print_custom_2", "abc");
shipment.options.Add("print_custom_3", "xyz");

shipment.Create();
var lowestRate = shipment.LowestRate(includeServices: new List<string>() { "First" }, includeCarriers: new List<string>() { "USPS" });

shipment.Buy(lowestRate);

shipment.GenerateLabel("pdf");