Search code examples
shippo

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


I am trying to use Shippo in my c# development for the first time and I was able to generate a label using the default USPS carrier, but I am unable to use the UPS account I setup on their website.

I am using this code to retrieve all the carriers, but the UPS account I created is not in the list, although I see it online.

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

This returns the 5 default accounts, although I can see that it is showing the ones I deactivated as active=false, so I know it is pulling from my account, but the collection doesn't include the UPS account I see online.

If I try to create the UPS carrier, I get an error that the carrier already exists:

// 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);

Exception Thrown: An unhandled exception of type 'Shippo.ShippoException' occurred in Shippo.dll

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

How do I retrieve the UPS carrier that I see is added to my account so that I can use it in a shipment?


Solution

  • When you connect a carrier account to Shippo, you can do so either programmatically using the Carrier Accounts endpoint or through the dashboard. In either scenario, you'll want to be careful of whether you have test enabled or not.

    If you're using your test Shippo token, its very likely that your UPS account is not flagged as test: true, which is preventing this from showing up in the list of available carriers.

    If you're certain it is in the right mode and you're using the right token, you'll also want to be sure to pass {results: 10}(or higher value if you have more carrier accounts connected). Since you're using C#, that would look something like:

    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.
    }
    

    You can find more about filtering results at https://goshippo.com/docs/filtering and https://goshippo.com/docs/carrier-accounts or check out the API references at https://goshippo.com/docs/reference