using 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 response
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default, an API error will raise a Shippo.Models.Errors.SDKException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
Message |
string | The error message |
StatusCode |
int | The HTTP status code |
RawResponse |
HttpResponseMessage | The raw HTTP response |
Body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the InitiateOauth2SigninAsync
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Shippo.Models.Errors.InitiateOauth2SigninResponseBody | 400 | application/json |
Shippo.Models.Errors.InitiateOauth2SigninCarrierAccountsResponseBody | 401 | application/json |
Shippo.Models.Errors.InitiateOauth2SigninCarrierAccountsResponseResponseBody | 404 | application/json |
Shippo.Models.Errors.SDKException | 4XX, 5XX | */* |
using Shippo;
using Shippo.Models.Requests;
using Shippo.Models.Components;
using System;
using Shippo.Models.Errors;
var sdk = new ShippoSDK(
apiKeyHeader: "<YOUR_API_KEY_HERE>",
shippoApiVersion: "2018-02-08"
);
try
{
InitiateOauth2SigninRequest req = new InitiateOauth2SigninRequest() {
CarrierAccountObjectId = "<id>",
RedirectUri = "https://enlightened-mortise.com/",
};
var res = await sdk.CarrierAccounts.InitiateOauth2SigninAsync(req);
// handle response
}
catch (Exception ex)
{
if (ex is InitiateOauth2SigninResponseBody)
{
// Handle exception data
throw;
}
else if (ex is InitiateOauth2SigninCarrierAccountsResponseBody)
{
// Handle exception data
throw;
}
else if (ex is InitiateOauth2SigninCarrierAccountsResponseResponseBody)
{
// Handle exception data
throw;
}
else if (ex is Shippo.Models.Errors.SDKException)
{
// Handle default exception
throw;
}
}
The default server can also be overridden globally by passing a URL to the serverUrl: string
optional parameter when initializing the SDK client instance. For example:
using Shippo;
using Shippo.Models.Requests;
using Shippo.Models.Components;
var sdk = new ShippoSDK(
serverUrl: "https://api.goshippo.com",
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
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
APIKeyHeader |
apiKey | API key |
To authenticate with the API the APIKeyHeader
parameter must be set when initializing the SDK client instance. For example:
using 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 response