如何检索我在我的 Shippo 帐户中设置的 UPS 承运人

How to retrieve the UPS carrier I setup in my Shippo account

我第一次尝试在我的 c# 开发中使用 Shippo,我能够使用默认的 USPS 承运人生成标签,但我无法使用我在他们网站上设置的 UPS 帐户。

我正在使用此代码检索所有承运人,但我创建的 UPS 帐户不在列表中,尽管我在网上看到它。

ShippoCollection<CarrierAccount> carriers = resource.AllCarrierAccount();

这 returns 5 个默认帐户,虽然我可以看到它显示我停用的帐户为 active=false,所以我知道它是从我的帐户中提取的,但集合不包括我在网上看到的 UPS 帐户。

如果我尝试创建 UPS 承运人,我收到承运人已存在的错误消息:

// Setup our UPS account as carrier
Hashtable accountTable = new Hashtable ();
accountTable.Add ("carrier", "ups");
accountTable.Add ("account_id", "******");
accountTable.Add ("parameters", new Hashtable()
{
    {"password", "*****"},
    {"account_number", "*****"},
    {"surepost", false},
    {"cost_center", "shippo"},
    {"USPS_endorsement", "3"}
});
accountTable.Add ("test", true);
accountTable.Add ("active", true);

CarrierAccount upsAccount = resource.CreateCarrierAccount(accountTable);

抛出异常: 'Shippo.ShippoException' 类型的未处理异常发生在 Shippo.dll

附加信息:{"non_field_errors":["An Account with account_id shark92651 already exists. You can update the existing account parameters using a PUT request"]}

如何检索我看到的已添加到我的帐户的 UPS 承运人,以便我可以在货件中使用它?

当您将承运人帐户连接到 Shippo 时,您可以使用 Carrier Accounts endpoint 以编程方式或通过仪表板进行此操作。在任何一种情况下,您都需要注意是否启用了 test

如果您使用的是测试 Shippo 令牌,很可能您的 UPS 帐户未被标记为 test: true,这会阻止它出现在可用承运人列表中。

如果您确定它处于正确的模式并且您使用的是正确的令牌,您还需要确保传递 {results: 10}(如果您有更多运营商帐户,则可以传递更高的值连接的)。由于您使用的是 C#,因此看起来像:

APIResource resource = new APIResource("<Shippo Token>");
Hashtable parameters = new Hashtable();
parameters.Add('results', 10);
ShippoCollection<CarrierAccount> carrierAccounts = resource.AllCarrierAccount(parameters);

foreach (CarrierAccount account in carrierAccounts) {
    // Do stuff to find the CarrierAccount that you're looking to retrieve.
}

您可以在 https://goshippo.com/docs/filtering and https://goshippo.com/docs/carrier-accounts or check out the API references at https://goshippo.com/docs/reference

找到有关筛选结果的更多信息