cancel
Showing results for 
Search instead for 
Did you mean: 
In recognition of the Presidents Day holiday, our Support office will be open with limited availability on Monday 02/18 from 10:00 am - 6:00 pm ET. Check out our Help Center for all the ways to get in touch with us and get help.

Beginner C# V3 API Example

Occasional Visitor

Beginner C# V3 API Example

I'm attempting to use the API for a C# ASP.net project.  Unfortunately most of the examples seem to be around Version 2 of the API, or in PHP.  I'm mostly just looking to get a list of contacts.  Is there example code for C# that might be around, that shows the authentication, refresh of key and downloading a contact list?

 

1 REPLY 1
Highlighted
Moderator

Re: Beginner C# V3 API Example

Hello,

Thank you for reaching out to Constant Contact API Developer Support.

Here is an example of what a call to obtain an access token might look like:

string authorization_code = "{authorization code}"
var client = new RestClient("https://idfed.constantcontact.com/as/token.oauth2?code="+ authorization_code +"&redirect_uri={redirect URI}&grant_type=authorization_code&client_secret={secret}");
var request = new RestRequest(Method.POST);
 
string credentials = "{api key}:{secret}"
byte[] plain = System.Text.Encoding.UTF8.GetBytes(credentials);
base64cred = Convert.ToBase64String(plain);
var base64auth = "Basic " + base64cred;
request.AddHeader("authorization", base64auth);
 
IRestResponse response = client.Execute(request);


Note that this is what your app would do once the user is redirected to your app after allowing access during the OAuth process. You can use the RestRequest method to make other calls, such as POST calls to refresh the token.

Please have a look and let me know if you have any questions!

Regards,
David B.
Tier II API Support Engineer