Shippo is a shipping API that connects you with multiple shipping carriers (such as USPS, UPS, DHL, Canada Post, Australia Post, and many others) through one interface.
You must register for a Shippo account to use our API. It's free to sign up. Only pay to print a live label, test labels are free.
To use the API, you must generate an API Token. In the following examples, replace <YOUR_API_KEY_HERE> with your own token.
For example.
apiKeyHeader:"shippo_test_595d9cb0c0e14497bf07e75ecfec6c6d"
Shippo external API.: Use this API to integrate with the Shippo service
- SDK Installation
- SDK Example Usage
- Available Resources and Operations
- Error Handling
- Server Selection
- Authentication
To add the NuGet package to a .NET project:
dotnet add package ShippoTo add a reference to a local instance of the SDK in a .NET project:
dotnet add reference Shippo/Shippo.csprojusing Shippo;
using Shippo.Models.Requests;
using Shippo.Models.Components;
var sdk = new ShippoSDK(
apiKeyHeader: "<YOUR_API_KEY_HERE>",
shippoApiVersion: "2018-02-08"
);
var res = await sdk.Addresses.ListAsync(
page: 1,
results: 5,
shippoApiVersion: "2018-02-08"
);
// handle responseThe C# SDK makes API calls using an ISpeakeasyHttpClient that wraps the native
HttpClient. This
client provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle
errors and response.
The ISpeakeasyHttpClient interface allows you to either use the default SpeakeasyHttpClient that comes with the SDK,
or provide your own custom implementation with customized configuration such as custom message handlers, timeouts,
connection pooling, and other HTTP client settings.
The following example shows how to create a custom HTTP client with request modification and error handling:
using Shippo;
using Shippo.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
// Create a custom HTTP client
public class CustomHttpClient : ISpeakeasyHttpClient
{
private readonly ISpeakeasyHttpClient _defaultClient;
public CustomHttpClient()
{
_defaultClient = new SpeakeasyHttpClient();
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
// Add custom header and timeout
request.Headers.Add("x-custom-header", "custom value");
request.Headers.Add("x-request-timeout", "30");
try
{
var response = await _defaultClient.SendAsync(request, cancellationToken);
// Log successful response
Console.WriteLine($"Request successful: {response.StatusCode}");
return response;
}
catch (Exception error)
{
// Log error
Console.WriteLine($"Request failed: {error.Message}");
throw;
}
}
public void Dispose()
{
_httpClient?.Dispose();
_defaultClient?.Dispose();
}
}
// Use the custom HTTP client with the SDK
var customHttpClient = new CustomHttpClient();
var sdk = new ShippoSDK(client: customHttpClient);You can also provide a completely custom HTTP client with your own configuration:
using Shippo.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
// Custom HTTP client with custom configuration
public class AdvancedHttpClient : ISpeakeasyHttpClient
{
private readonly HttpClient _httpClient;
public AdvancedHttpClient()
{
var handler = new HttpClientHandler()
{
MaxConnectionsPerServer = 10,
// ServerCertificateCustomValidationCallback = customCertValidation, // Custom SSL validation if needed
};
_httpClient = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(30)
};
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
return await _httpClient.SendAsync(request, cancellationToken ?? CancellationToken.None);
}
public void Dispose()
{
_httpClient?.Dispose();
}
}
var sdk = ShippoSDK.Builder()
.WithClient(new AdvancedHttpClient())
.Build();For simple debugging, you can enable request/response logging by implementing a custom client:
public class LoggingHttpClient : ISpeakeasyHttpClient
{
private readonly ISpeakeasyHttpClient _innerClient;
public LoggingHttpClient(ISpeakeasyHttpClient innerClient = null)
{
_innerClient = innerClient ?? new SpeakeasyHttpClient();
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
{
// Log request
Console.WriteLine($"Sending {request.Method} request to {request.RequestUri}");
var response = await _innerClient.SendAsync(request, cancellationToken);
// Log response
Console.WriteLine($"Received {response.StatusCode} response");
return response;
}
public void Dispose() => _innerClient?.Dispose();
}
var sdk = new ShippoSDK(client: new LoggingHttpClient());The SDK also provides built-in hook support through the SDKConfiguration.Hooks system, which automatically handles
BeforeRequestAsync, AfterSuccessAsync, and AfterErrorAsync hooks for advanced request lifecycle management.
Review our full guides and references at https://docs.goshippo.com/.
Available methods
- List - List all addresses
- Create - Create a new address
- Get - Retrieve an address
- Validate - Validate an address
- Create - Create a batch
- Get - Retrieve a batch
- AddShipments - Add shipments to a batch
- Purchase - Purchase a batch
- RemoveShipments - Remove shipments from a batch
- List - List all carrier accounts
- Create - Create a new carrier account
- Get - Retrieve a carrier account
- Update - Update a carrier account
- InitiateOauth2Signin - Connect an existing carrier account using OAuth 2.0
- Register - Add a Shippo carrier account
- GetRegistrationStatus - Get Carrier Registration status
- List - List all customs declarations
- Create - Create a new customs declaration
- Get - Retrieve a customs declaration
- Create - Create a pickup
- Get - Retrieve a rate
- ListShipmentRates - Retrieve shipment rates
- ListShipmentRatesByCurrencyCode - Retrieve shipment rates in currency
- Create - Generate a live rates request
- GetDefaultParcelTemplate - Show current default parcel template
- UpdateDefaultParcelTemplate - Update default parcel template
- DeleteDefaultParcelTemplate - Clear current default parcel template
- List - List all service groups
- Create - Create a new service group
- Update - Update an existing service group
- Delete - Delete a service group
- List - List all Shippo Accounts
- Create - Create a Shippo Account
- Get - Retrieve a Shippo Account
- Update - Update a Shippo Account
- List - List all user parcel templates
- Create - Create a new user parcel template
- Delete - Delete a user parcel template
- Get - Retrieves a user parcel template
- Update - Update an existing user parcel template
- CreateWebhook - Create a new webhook
- ListWebhooks - List all webhooks
- GetWebhook - Retrieve a specific webhook
- UpdateWebhook - Update an existing webhook
- DeleteWebhook - Delete a specific webhook
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!
Connect with multiple different carriers, get discounted shipping labels, track parcels, and much more with just one integration. You can use your own carrier accounts or take advantage of our discounted rates with the Shippo carrier accounts. Using Shippo makes it easy to deal with multiple carrier integrations, rate shopping, tracking and other parts of the shipping workflow. We provide the API and web app for all your shipping needs.