Got a 'How do I' question? Join 'Ask a Trainer' Monday to Friday, 11am to 4pm ET for instant help and pro tips!

ASP.NET MVC integration

FadyY8
Campaign Collaborator
0 Votes

Hello,

I have spent a total of 30 hours so far trying to integrate your API endpoints with MVC project that my company has.

Do you have any C# examples I can look at?

This is my snippet but I am getting an error (grant_type is required).

 

 

            if (Request.QueryString["access_token"] != null)

            {

                code = Request.QueryString["access_token"];           

                ResponseAPI response = new ResponseAPI();

                try

                {

                    using (var webClient = new WebClient())

                    {

                        byte[] bytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(apiKey + ":" + client_secret);

                        string encodedData = Convert.ToBase64String(bytes);

                        string _params = "redirect_uri=https://localhost&grant_type=authorization_code&code=" + code;

                        var url = "https://idfed.constantcontact.com/as/token.oauth2";

 

                        webClient.Headers.Add("Accept", "application/json");

                        webClient.Headers.Add("Authorization", "Basic " + encodedData);

                        

                        response.Response = webClient.UploadString(url, "POST", _params);

                    }

                }

                catch (WebException we)

                {

                    using (var sr = new StreamReader(we.Response.GetResponseStream()))

                    {

                        response.Response = sr.ReadToEnd();

                    }

                }           

}

1 REPLY 1
Courtney_E
Moderator
0 Votes

Thank you for reaching out to Constant Contact API Developer Support, and for your patience. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

Based on the code provided, as well as your comment on this post, it looks like you were able to resolve the grant_type error you had been running into. Also, you shouldn't need to be logged into the developer portal for the account to stay authorized if you have completed the OAuth2.0 flow to grant access to the Constant Contact account you'll be working with.

 

The request for V3 application code samples is currently under review. However, we're currently still adding endpoints and capabilities to the V3 API, and do not plan to publish official SDKs or sample apps until that process is complete. Your feedback and experience with this request is essential to improving our product, so thank you for reaching out to us regarding this matter.

 

In the meantime, here are the sample calls that are currently available for V3:

https://v3.developer.constantcontact.com/api_guide/tag_code_samples.html

 

If you still need assistance with this, please let us know!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up