using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(req);
while(res != null)
{
// handle items
res = await res.Next!();
}This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
ApiKey |
http | HTTP Bearer |
To authenticate with the API the ApiKey parameter must be set when initializing the SDK client instance. For example:
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"
);
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(req);
while(res != null)
{
// handle items
res = await res.Next!();
}Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned response object will have a Next method that can be called to pull down the next group of results. If the
return value of Next is null, then there are no more pages to be fetched.
Here's an example of one such pagination call:
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(req);
while(res != null)
{
// handle items
res = await res.Next!();
}Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply pass a RetryConfig to the call:
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
request: req
);
while(res != null)
{
// handle items
res = await res.Next!();
}If you'd like to override the default retry strategy for all operations that support retries, you can use the RetryConfig optional parameter when intitializing the SDK:
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(req);
while(res != null)
{
// handle items
res = await res.Next!();
}BaseException is the base exception class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
|---|---|---|
Message |
string | Error message |
Request |
HttpRequestMessage | HTTP request object |
Response |
HttpResponseMessage | HTTP response object |
Some exceptions in this SDK include an additional Payload field, which will contain deserialized custom error data when present. Possible exceptions are listed in the Error Classes section.
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Errors;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
try
{
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(req);
while(res != null)
{
// handle items
res = await res.Next!();
}
}
catch (BaseException ex) // all SDK exceptions inherit from BaseException
{
// ex.ToString() provides a detailed error message
System.Console.WriteLine(ex);
// Base exception fields
HttpRequestMessage request = ex.Request;
HttpResponseMessage response = ex.Response;
var statusCode = (int)response.StatusCode;
var responseBody = ex.Body;
if (ex is BadRequestResponse) // different exceptions may be thrown depending on the method
{
// Check error data fields
BadRequestResponsePayload payload = ex.Payload;
double StatusCode = payload.StatusCode;
string Error = payload.Error;
// ...
}
// An underlying cause may be provided
if (ex.InnerException != null)
{
Exception cause = ex.InnerException;
}
}
catch (System.Net.Http.HttpRequestException ex)
{
// Check ex.InnerException for Network connectivity errors
}Primary exceptions:
BaseException: The base class for HTTP error responses.UnauthorizedResponse: Unauthorized. Status code401. *PaymentRequiredResponse: Payment Required. Status code402. *NotFoundResponse: The specified resource was not found. Status code404. *BadRequestResponse: Bad Request. Status code400. *UnprocessableResponse: Unprocessable. Status code422. *
Less common exceptions (3)
-
System.Net.Http.HttpRequestException: Network connectivity error. For more details about the underlying cause, inspect theex.InnerException. -
Inheriting from
BaseException:Unauthorized: Unauthorized. Status code401. Applicable to 6 of 336 methods.*ResponseValidationError: Thrown when the response data could not be deserialized into the expected type.
* Refer to the relevant documentation to determine whether an exception applies to a specific operation.
The default server can be overridden globally by passing a URL to the serverUrl: string optional parameter when initializing the SDK client instance. For example:
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System.Collections.Generic;
var sdk = new Apideck(
serverUrl: "https://unify.apideck.com",
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
AccountingTaxRatesAllRequest req = new AccountingTaxRatesAllRequest() {
ServiceId = "salesforce",
CompanyId = "12345",
Filter = new TaxRatesFilter() {
Assets = true,
Equity = true,
Expenses = true,
Liabilities = true,
Revenue = true,
},
PassThrough = new Dictionary<string, object>() {
{ "search", "San Francisco" },
},
Fields = "id,updated_at",
};
AccountingTaxRatesAllResponse? res = await sdk.Accounting.TaxRates.ListAsync(req);
while(res != null)
{
// handle items
res = await res.Next!();
}The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
using ApideckUnifySdk;
using ApideckUnifySdk.Models.Components;
using ApideckUnifySdk.Models.Requests;
using System;
var sdk = new Apideck(
consumerId: "test-consumer",
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
apiKey: "<YOUR_BEARER_TOKEN_HERE>"
);
AccountingAttachmentsUploadRequest req = new AccountingAttachmentsUploadRequest() {
ReferenceType = AttachmentReferenceType.Invoice,
ReferenceId = "123456",
XApideckMetadata = "{\"name\":\"document.pdf\",\"description\":\"Invoice attachment\"}",
ServiceId = "salesforce",
RequestBody = System.Text.Encoding.UTF8.GetBytes("0x506D4BD16D"),
};
var res = await sdk.Accounting.Attachments.UploadAsync(
request: req,
serverUrl: "https://upload.apideck.com"
);
// 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 ApideckUnifySdk;
using ApideckUnifySdk.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 Apideck(client: customHttpClient);You can also provide a completely custom HTTP client with your own configuration:
using ApideckUnifySdk.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 = Apideck.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 Apideck(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.