Gr4vy 2.3.1

dotnet add package Gr4vy --version 2.3.1
                    
NuGet\Install-Package Gr4vy -Version 2.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gr4vy" Version="2.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gr4vy" Version="2.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Gr4vy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Gr4vy --version 2.3.1
                    
#r "nuget: Gr4vy, 2.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Gr4vy@2.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Gr4vy&version=2.3.1
                    
Install as a Cake Addin
#tool nuget:?package=Gr4vy&version=2.3.1
                    
Install as a Cake Tool

gr4vy

SDK Example Usage

Example

using Gr4vy;
using Gr4vy.Models.Components;
using System.Collections.Generic;

var sdk = new Gr4vySDK(
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

var res = await sdk.AccountUpdater.Jobs.CreateAsync(accountUpdaterJobCreate: new AccountUpdaterJobCreate() {
    PaymentMethodIds = new List<string>() {
        "ef9496d8-53a5-4aad-8ca2-00eb68334389",
        "f29e886e-93cc-4714-b4a3-12b7a718e595",
    },
});

// handle response

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
BearerAuth http HTTP Bearer

To authenticate with the API the BearerAuth parameter must be set when initializing the SDK client instance. For example:

using Gr4vy;
using Gr4vy.Models.Components;
using System.Collections.Generic;

var sdk = new Gr4vySDK(
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
    merchantAccountId: "default"
);

var res = await sdk.AccountUpdater.Jobs.CreateAsync(accountUpdaterJobCreate: new AccountUpdaterJobCreate() {
    PaymentMethodIds = new List<string>() {
        "ef9496d8-53a5-4aad-8ca2-00eb68334389",
        "f29e886e-93cc-4714-b4a3-12b7a718e595",
    },
});

// handle response

Global Parameters

A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.

For example, you can set merchant_account_id to `` at SDK initialization and then you do not have to pass the same value on calls to operations like Get. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.

Available Globals

The following global parameter is available.

Name Type Description
merchantAccountId string The ID of the merchant account to use for this request.

Example

using Gr4vy;
using Gr4vy.Models.Components;

var sdk = new Gr4vySDK(
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

var res = await sdk.MerchantAccounts.GetAsync(merchantAccountId: "merchant-12345");

// handle response

Pagination

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 Gr4vy;
using Gr4vy.Models.Components;
using Gr4vy.Models.Requests;

var sdk = new Gr4vySDK(
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

ListBuyersRequest req = new ListBuyersRequest() {
    Cursor = "ZXhhbXBsZTE",
    Search = "John",
    ExternalIdentifier = "buyer-12345",
};

ListBuyersResponse? res = await sdk.Buyers.ListAsync(req);

while(res != null)
{
    // handle items

    res = await res.Next!();
}

Retries

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 Gr4vy;
using Gr4vy.Models.Components;
using Gr4vy.Models.Requests;

var sdk = new Gr4vySDK(
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

ListBuyersRequest req = new ListBuyersRequest() {
    Cursor = "ZXhhbXBsZTE",
    Search = "John",
    ExternalIdentifier = "buyer-12345",
};

ListBuyersResponse? res = await sdk.Buyers.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 Gr4vy;
using Gr4vy.Models.Components;
using Gr4vy.Models.Requests;

var sdk = new Gr4vySDK(
    retryConfig: new RetryConfig(
        strategy: RetryConfig.RetryStrategy.BACKOFF,
        backoff: new BackoffStrategy(
            initialIntervalMs: 1L,
            maxIntervalMs: 50L,
            maxElapsedTimeMs: 100L,
            exponent: 1.1
        ),
        retryConnectionErrors: false
    ),
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

ListBuyersRequest req = new ListBuyersRequest() {
    Cursor = "ZXhhbXBsZTE",
    Search = "John",
    ExternalIdentifier = "buyer-12345",
};

ListBuyersResponse? res = await sdk.Buyers.ListAsync(req);

while(res != null)
{
    // handle items

    res = await res.Next!();
}

Error Handling

BaseException is the base exception class for all HTTP error responses. It has the following properties:

Property Type Description
Message string Error message
StatusCode int HTTP status code
Headers HttpResponseHeaders HTTP headers
ContentType string? HTTP content type
RawResponse HttpResponseMessage HTTP response object
Body string HTTP response body

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.

Example

using Gr4vy;
using Gr4vy.Models.Components;
using Gr4vy.Models.Errors;
using System.Collections.Generic;

var sdk = new Gr4vySDK(
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

try
{
    var res = await sdk.AccountUpdater.Jobs.CreateAsync(accountUpdaterJobCreate: new AccountUpdaterJobCreate() {
        PaymentMethodIds = new List<string>() {
            "ef9496d8-53a5-4aad-8ca2-00eb68334389",
            "f29e886e-93cc-4714-b4a3-12b7a718e595",
        },
    });

    // handle response
}
catch (BaseException ex)  // all SDK exceptions inherit from BaseException
{
    // ex.ToString() provides a detailed error message
    System.Console.WriteLine(ex);

    // Base exception fields
    HttpResponseMessage rawResponse = ex.RawResponse;
    HttpResponseHeaders headers = ex.Headers;
    int statusCode = ex.StatusCode;
    string? contentType = ex.ContentType;
    var responseBody = ex.Body;

    if (ex is Error400) // different exceptions may be thrown depending on the method
    {
        // Check error data fields
        Error400Payload payload = ex.Payload;
        string Type = payload.Type;
        string Code = payload.Code;
        // ...
    }

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

Error Classes

Primary exceptions:

  • BaseException: The base class for HTTP error responses.
    • Error400: The request was invalid. Status code 400.
    • Error401: The request was unauthorized. Status code 401.
    • Error403: The credentials were invalid or the caller did not have permission to act on the resource. Status code 403.
    • Error404: The resource was not found. Status code 404.
    • Error405: The request method was not allowed. Status code 405.
    • Error409: A duplicate record was found. Status code 409.
    • Error425: The request was too early. Status code 425.
    • Error429: Too many requests were made. Status code 429.
    • Error500: The server encountered an error. Status code 500.
    • Error502: The server encountered an error. Status code 502.
    • Error504: The server encountered an error. Status code 504.
    • HTTPValidationError: Validation Error. Status code 422. *

<details><summary>Less common exceptions (2)</summary>

* Refer to the relevant documentation to determine whether an exception applies to a specific operation.

Server Selection

Select Server by Name

You can override the default server globally by passing a server name to the server: string optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:

Name Server Variables Description
sandbox https://api.sandbox.{id}.gr4vy.app id
production https://api.{id}.gr4vy.app id

If the selected server has variables, you may override its default values through the additional parameters made available in the SDK constructor:

Variable Parameter Default Description
id id: string "example" The subdomain for your Gr4vy instance.
Example
using Gr4vy;
using Gr4vy.Models.Components;
using System.Collections.Generic;

var sdk = new Gr4vySDK(
    server: SDKConfig.Server.Production,
    id: "<id>",
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

var res = await sdk.AccountUpdater.Jobs.CreateAsync(accountUpdaterJobCreate: new AccountUpdaterJobCreate() {
    PaymentMethodIds = new List<string>() {
        "ef9496d8-53a5-4aad-8ca2-00eb68334389",
        "f29e886e-93cc-4714-b4a3-12b7a718e595",
    },
});

// handle response

Override Server URL Per-Client

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 Gr4vy;
using Gr4vy.Models.Components;
using System.Collections.Generic;

var sdk = new Gr4vySDK(
    serverUrl: "https://api.sandbox.example.gr4vy.app",
    merchantAccountId: "default",
    bearerAuth: "<YOUR_BEARER_TOKEN_HERE>"
);

var res = await sdk.AccountUpdater.Jobs.CreateAsync(accountUpdaterJobCreate: new AccountUpdaterJobCreate() {
    PaymentMethodIds = new List<string>() {
        "ef9496d8-53a5-4aad-8ca2-00eb68334389",
        "f29e886e-93cc-4714-b4a3-12b7a718e595",
    },
});

// handle response

Custom HTTP Client

The 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 Gr4vy;
using Gr4vy.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 Gr4vy(client: customHttpClient);

<details> <summary>You can also provide a completely custom HTTP client with your own configuration:</summary>

using Gr4vy.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 = Gr4vy.Builder()
    .WithClient(new AdvancedHttpClient())
    .Build();

</details>

<details> <summary>For simple debugging, you can enable request/response logging by implementing a custom client:</summary>

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 Gr4vy(client: new LoggingHttpClient());

</details>

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.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.1 124 10/22/2025
2.3.0 160 10/20/2025
2.2.5 179 10/14/2025
2.2.4 164 10/14/2025
2.2.3 237 10/8/2025
2.2.2 166 10/8/2025
2.2.1 167 10/6/2025
2.2.0 159 10/6/2025
2.1.0 172 10/2/2025
2.0.2 164 10/1/2025
2.0.1 179 10/1/2025
2.0.0 165 9/29/2025
1.2.13 178 9/25/2025
1.2.12 173 9/23/2025
1.2.11 160 9/23/2025
1.2.10 169 9/22/2025
1.2.9 643 9/16/2025
1.2.8 301 9/16/2025
1.2.7 300 9/16/2025
1.2.6 187 9/11/2025
1.2.5 170 9/11/2025
1.2.4 175 9/9/2025
1.2.3 168 9/9/2025
1.2.2 195 9/3/2025
1.2.1 233 8/28/2025
1.2.0 212 8/27/2025
1.1.31 304 8/21/2025
1.1.30 163 8/20/2025
1.1.29 166 8/20/2025
1.1.28 163 8/18/2025
1.1.27 1,432 8/14/2025
1.1.26 171 8/13/2025
1.1.25 165 8/11/2025
1.1.24 244 8/7/2025
1.1.23 246 8/7/2025
1.1.22 245 8/6/2025
1.1.21 250 8/5/2025
1.1.20 184 8/4/2025
1.1.19 168 8/4/2025
1.1.18 127 7/31/2025
1.1.17 127 7/30/2025
1.1.16 124 7/30/2025
1.1.15 132 7/28/2025
1.1.14 138 7/28/2025
1.1.13 138 7/28/2025
1.1.12 507 7/24/2025
1.1.11 501 7/24/2025
1.1.10 553 7/23/2025
1.1.9 540 7/22/2025
1.1.8 439 7/21/2025
1.1.7 167 7/16/2025
1.1.6 168 7/15/2025
1.1.5 173 7/14/2025
1.1.4 170 7/9/2025
1.1.3 167 7/8/2025
1.1.2 170 7/8/2025
1.1.1 116 7/4/2025
1.1.0 172 7/3/2025
1.0.4 181 6/26/2025
1.0.3 381 6/25/2025
1.0.2 171 6/24/2025
1.0.1 256 6/23/2025
1.0.0 139 6/20/2025
1.0.0-beta.21 213 6/16/2025
1.0.0-beta.20 126 6/16/2025
1.0.0-beta.19 131 6/5/2025
1.0.0-beta.18 126 6/5/2025
1.0.0-beta.17 134 6/5/2025
1.0.0-beta.16 126 6/4/2025
1.0.0-beta.15 132 6/4/2025
1.0.0-beta.14 134 6/4/2025
1.0.0-beta.13 131 6/3/2025
1.0.0-beta.12 130 6/3/2025
1.0.0-beta.11 134 6/3/2025
1.0.0-beta.10 132 6/3/2025
1.0.0-beta.9 96 5/30/2025
1.0.0-beta.8 140 5/29/2025
1.0.0-beta.7 134 5/29/2025
1.0.0-beta.6 132 5/28/2025
1.0.0-beta.5 136 5/27/2025
1.0.0-beta.4 141 5/21/2025
1.0.0-beta.3 142 5/20/2025
1.0.0-beta.2 139 5/19/2025
1.0.0-beta.1 172 5/16/2025
0.0.18 237 5/16/2025
0.0.13 297 5/12/2025
0.0.12 247 5/12/2025
0.0.11 249 5/12/2025
0.0.10 250 5/12/2025
0.0.5 254 5/12/2025
0.0.4 251 5/12/2025