This topic provides instructions for installing the Constant Contact V3 C# (.NET) SDK.
Install Package Requirements
- RestSharp - 106.13.0 or later
- Json.NET - 13.0.2 or later
- JsonSubTypes - 1.8.0 or later
- System.ComponentModel.Annotations - 5.0.0 or later
Constant Contact recommends using NuGet to obtain the latest version of the following packages:
- Install-Package RestSharp
- NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742.
- NOTE: RestSharp for .Net Core creates a new socket for each api call, which can lead to a socket exhaustion problem. See RestSharp#1406.
- Install-Package Newtonsoft.Json
- Install-Package JsonSubTypes
- Install-Package System.ComponentModel.Annotations
Generate and Include the DLL
- Generate the DLL by running one of the commands that follow.
- For [Mac/Linux]:
/bin/sh build.sh - For [Windows]:
build.bat
- For [Mac/Linux]:
-
Include the DLL under the bin folder in the C# project, and use the following namespaces:
using ConstantContactApi.Api;using ConstantContactApi.Client;using ConstantContactApi.Model;
Build the Package
Follow the Nuget quickstart to install and publish packages.
-
The
.nuspecis included in the project and because it uses placeholders from the .csproj. You must build the.csprojdirectly:nuget pack -Build -OutputDirectory out ConstantContactApi.csproj - Publish the package to a local feed or to another host.
- Consume the new package using Nuget.
Using the API Client with an HTTP Proxy
To use the API client with an HTTP proxy, you must set up a System.New.WebProxy. For example:
Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;
Example
The following code example uses the AddAccountEmailAddress method to create a new account email address in a Constant Contact account.
using System.Collections.Generic;
using System.Diagnostics;
using ConstantContactApi.Api;
using ConstantContactApi.Client;
using ConstantContactApi.Model;
namespace Example
{
public class Example
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "https://l1.api.cc.email/v3";
// Configure OAuth2 accesstoken for authorization: oauth2_access_code
config.AccessToken = "YOUR_ACCESS_TOKEN";
// Configure OAuth2 access token for authorization: oauth2_implicit
config.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new AccountServicesApi(config);
var addAccountEmailAddressRequest = new AddAccountEmailAddressRequest(); // AddAccountEmailAddressRequest | A JSON request payload containing the new email address you want to add to the Constant Contact account.
try
{
// POST Add an Account Email Address
AddAccountEmailAddress201Response result = apiInstance.AddAccountEmailAddress(addAccountEmailAddressRequest);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling AccountServicesApi.AddAccountEmailAddress: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
Learn More
To learn more about this SDK, visit:
-
Our C# GitHub repository.