Skip to content

goshippo/shippo-csharp-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shippo logo Shippo C# SDK

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"

SDK Installation

NuGet

dotnet add package Shippo

Locally

dotnet add reference path/to/Shippo.csproj

SDK Example Usage

Example

using Shippo;
using Shippo.Models.Components;
using Shippo.Models.Requests;

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 response

Custom HTTP Client

The following is taken from Speakeasy's C# design:

By default the C# SDK will instantiate its own SpeakeasyHttpClient, which uses the System.Net.HttpClient under the hood. The default client can be overridden by passing a custom HTTP client when initializing the SDK:

var sdk = new ShippoSDK(client: new CustomHttpClient());

The provided HTTP Client must implement the ISpeakeasyHttpClient interface as defined in Utils.SpeakeasyHttpClient.cs: ...

This can be useful if you want to use a custom HTTP Client that supports a proxy or other custom configuration.

Below is an example of custom client that inherits from the internal SpeakeasyHttpClient class, which itself implements the ISpekeasyHttpClient interface. This client simply adds a header to all requests before sending them:

using Shippo.Utils;

public class CustomHttpClient : SpeakeasyHttpClient
{
    public CustomHttpClient() {}

    public override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
    {
        request.Headers.Add("X-Custom-Header", "custom value");
        return await base.SendAsync(request);
    }
}

A further example is included in the ShippoTests project in this repo.

Documentation

Review our full guides and references at https://docs.goshippo.com/.

Available Resources and Operations

  • List - List all addresses
  • Create - Create a new address
  • Get - Retrieve an address
  • Validate - Validate an address
  • List - List all customs declarations
  • Create - Create a new customs declaration
  • Get - Retrieve a customs declaration
  • List - List all customs items
  • Create - Create a new customs item
  • Get - Retrieve a customs item
  • List - List all manifests
  • Create - Create a new manifest
  • Get - Retrieve a manifest
  • List - List all orders
  • Create - Create a new order
  • Get - Retrieve an order
  • List - List all carrier parcel templates
  • Get - Retrieve a carrier parcel templates
  • List - List all parcels
  • Create - Create a new parcel
  • Get - Retrieve an existing parcel
  • Create - Create a refund
  • List - List all refunds
  • Get - Retrieve a refund
  • 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 shipments
  • Create - Create a new shipment
  • Get - Retrieve a shipment
  • Create - Register a tracking webhook
  • Get - Get a tracking status
  • List - List all shipping labels
  • Create - Create a shipping label
  • Get - Retrieve a shipping label
  • 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
  • List - List all Shippo Accounts
  • Create - Create a Shippo Account
  • Get - Retrieve a Shippo Account
  • Update - Update a Shippo Account

Development

Contributions

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!

About Shippo

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.