Skip to content

Latest commit

 

History

History
1352 lines (1106 loc) · 68.5 KB

File metadata and controls

1352 lines (1106 loc) · 68.5 KB

Cvent.SDK

Developer-friendly & type-safe Csharp SDK specifically catered to leverage Cvent.SDK API.

Summary

Cvent REST APIs: Official Cvent SDK providing typed access to Cvent REST APIs for event management, contacts, attendees, and more using OAuth2 authentication. For documentation, see the README and USAGE. To get credentials, visit https://developers.cvent.com/docs/rest-api/overview.

For more information about the API: Cvent Developer Documentation

Table of Contents

SDK Installation

NuGet

To add the NuGet package to a .NET project:

dotnet add package Cvent.SDK

Locally

To add a reference to a local instance of the SDK in a .NET project:

dotnet add reference src/Cvent/SDK/Cvent.SDK.csproj

SDK Example Usage

Example

using Cvent.SDK;
using Cvent.SDK.Models.Components;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK(security: new Security() {
    OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
        TokenURL = "<YOUR_TOKEN_URL_HERE>",
        Scopes = "<YOUR_SCOPES_HERE>",
    },
});

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(req);

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

    res = await res.Next!();
}

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

Name Type Scheme
OAuth2ClientCredentials oauth2 OAuth2 token
OAuth2AuthorizationCode oauth2 OAuth2 token

You can set the security parameters through the security optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:

using Cvent.SDK;
using Cvent.SDK.Models.Components;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK(security: new Security() {
    OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
        TokenURL = "<YOUR_TOKEN_URL_HERE>",
        Scopes = "<YOUR_SCOPES_HERE>",
    },
});

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(req);

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

    res = await res.Next!();
}

Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:

using Cvent.SDK;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK();

Oauth2TokenRequest req = new Oauth2TokenRequest() {
    GrantType = GrantType.ClientCredentials,
    ClientId = "djc98u3jiedmi283eu928",
    Scope = "event/events:read event/attendees:read",
    RedirectUri = "https://example.com/redirect",
    RefreshToken = "dn43ud8uj32nk2je",
    Code = "AUTHORIZATION_CODE",
};

var res = await sdk.Authentication.Oauth2TokenAsync(
    security: new Oauth2TokenSecurity() {
        Username = "",
        Password = "",
    },
    request: req
);

// handle response

Available Resources and Operations

Available methods

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

var sdk = new CventSDK(security: new Security() {
    OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
        TokenURL = "<YOUR_TOKEN_URL_HERE>",
        Scopes = "<YOUR_SCOPES_HERE>",
    },
});

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(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 Cvent.SDK;
using Cvent.SDK.Models.Components;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK(security: new Security() {
    OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
        TokenURL = "<YOUR_TOKEN_URL_HERE>",
        Scopes = "<YOUR_SCOPES_HERE>",
    },
});

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(
    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 Cvent.SDK;
using Cvent.SDK.Models.Components;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK(
    retryConfig: new RetryConfig(
        strategy: RetryConfig.RetryStrategy.BACKOFF,
        backoff: new BackoffStrategy(
            initialIntervalMs: 1L,
            maxIntervalMs: 50L,
            maxElapsedTimeMs: 100L,
            exponent: 1.1
        ),
        retryConnectionErrors: false
    ),
    security: new Security() {
        OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
            ClientID = "<YOUR_CLIENT_ID_HERE>",
            ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
            TokenURL = "<YOUR_TOKEN_URL_HERE>",
            Scopes = "<YOUR_SCOPES_HERE>",
        },
    }
);

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(req);

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

    res = await res.Next!();
}

Error Handling

CventSDKException 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.

Example

using Cvent.SDK;
using Cvent.SDK.Models.Components;
using Cvent.SDK.Models.Errors;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK(security: new Security() {
    OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
        TokenURL = "<YOUR_TOKEN_URL_HERE>",
        Scopes = "<YOUR_SCOPES_HERE>",
    },
});

try
{
    GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
        Token = "1a2b3c4d5e6f7g8h9i10j11k",
        Filter = "name eq 'My User Group'",
    };

    GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(req);

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

        res = await res.Next!();
    }
}
catch (CventSDKException ex) // all SDK exceptions inherit from CventSDKException
{
    // 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 Models.Errors.ErrorResponse) // different exceptions may be thrown depending on the method
    {
        // Check error data fields
        Models.Errors.ErrorResponsePayload payload = ex.Payload;
        long Code = payload.Code;
        string Message = payload.Message;
        // ...
    }

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

  • CventSDKException: The base class for HTTP error responses.
    • ErrorResponse: Represents an error response with additional details of cascading error messages. *
Less common exceptions (5)

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

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the serverIndex: int 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 indexes associated with the available servers:

# Server Description
0 https://api-platform.cvent.com/ea
1 https://api-platform-eur.cvent.com/ea

Example

using Cvent.SDK;
using Cvent.SDK.Models.Components;
using Cvent.SDK.Models.Requests;

var sdk = new CventSDK(
    serverIndex: 0,
    security: new Security() {
        OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
            ClientID = "<YOUR_CLIENT_ID_HERE>",
            ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
            TokenURL = "<YOUR_TOKEN_URL_HERE>",
            Scopes = "<YOUR_SCOPES_HERE>",
        },
    }
);

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(req);

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

    res = await res.Next!();
}

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

var sdk = new CventSDK(
    serverUrl: "https://api-platform-eur.cvent.com/ea",
    security: new Security() {
        OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
            ClientID = "<YOUR_CLIENT_ID_HERE>",
            ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
            TokenURL = "<YOUR_TOKEN_URL_HERE>",
            Scopes = "<YOUR_SCOPES_HERE>",
        },
    }
);

GetAccountUserGroupsRequest req = new GetAccountUserGroupsRequest() {
    Token = "1a2b3c4d5e6f7g8h9i10j11k",
    Filter = "name eq 'My User Group'",
};

GetAccountUserGroupsResponse? res = await sdk.Users.GetAccountUserGroupsAsync(req);

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

    res = await res.Next!();
}

Override Server URL Per-Operation

The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:

using Cvent.SDK;
using Cvent.SDK.Models.Components;

var sdk = new CventSDK(security: new Security() {
    OAuth2ClientCredentials = new SchemeOAuth2ClientCredentials() {
        ClientID = "<YOUR_CLIENT_ID_HERE>",
        ClientSecret = "<YOUR_CLIENT_SECRET_HERE>",
        TokenURL = "<YOUR_TOKEN_URL_HERE>",
        Scopes = "<YOUR_SCOPES_HERE>",
    },
});

CardTokenRequest req = new CardTokenRequest() {
    CreditCard = new CreditCardRequestJson() {
        AccountHolderName = "John Doe",
        ExpMonth = 11,
        ExpYear = 2026,
        Cvv = "123",
        AddressLine1 = "123 Main Street",
        AddressLine2 = "First Floor",
        AddressLine3 = "Apt 101",
        AddressCity = "McLean",
        AddressStateProvince = "VA",
        AddressPostalCode = "12345",
        AddressCountry = "USA",
        AddressCountryAlpha2 = "US",
        ContactPhone = "910-999-9999",
        Email = "jdoe@example.com",
        Number = "4111111111111111",
    },
};

var res = await sdk.CardTokens.CreateCardTokensAsync(
    request: req,
    serverUrl: "https://secure-ecommerce.api-platform.cvent.com/ea"
);

// 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 Cvent.SDK;
using Cvent.SDK.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 CventSDK(client: customHttpClient);
You can also provide a completely custom HTTP client with your own configuration:
using Cvent.SDK.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 = CventSDK.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 CventSDK(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.

License

This SDK is licensed under the MIT License. See LICENSE.txt for the full license text and third party notices.

Use of this SDK is subject to Cvent's Product Terms of Use.

<style> :root { --badge-gray-bg: #f3f4f6; --badge-gray-border: #d1d5db; --badge-gray-text: #374151; --badge-blue-bg: #eff6ff; --badge-blue-border: #3b82f6; --badge-blue-text: #3b82f6; } @media (prefers-color-scheme: dark) { :root { --badge-gray-bg: #374151; --badge-gray-border: #4b5563; --badge-gray-text: #f3f4f6; --badge-blue-bg: #1e3a8a; --badge-blue-border: #3b82f6; --badge-blue-text: #93c5fd; } } h1 { border-bottom: none !important; margin-bottom: 4px; margin-top: 0; letter-spacing: 0.5px; font-weight: 600; } .badge-text { letter-spacing: 1px; font-weight: 300; } .badge-container { display: inline-flex; align-items: center; background: var(--badge-gray-bg); border: 1px solid var(--badge-gray-border); border-radius: 6px; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 11px; text-decoration: none; vertical-align: middle; } .badge-container.blue { background: var(--badge-blue-bg); border-color: var(--badge-blue-border); } .badge-icon-section { padding: 4px 8px; border-right: 1px solid var(--badge-gray-border); display: flex; align-items: center; } .badge-text-section { padding: 4px 10px; color: var(--badge-gray-text); font-weight: 400; } .badge-container.blue .badge-text-section { color: var(--badge-blue-text); } .badge-link { text-decoration: none; margin-left: 8px; display: inline-flex; vertical-align: middle; } .badge-link:hover { text-decoration: none; } .badge-link:first-child { margin-left: 0; } .badge-icon-section svg { color: var(--badge-gray-text); } .badge-container.blue .badge-icon-section svg { color: var(--badge-blue-text); } </style>