cancel
Showing results for 
Search instead for 
Did you mean: 

Console Application V3 Get/UPDATE/ADD Contacts

Occasional Contributor

Console Application V3 Get/UPDATE/ADD Contacts

Hi all,

I am creating a Console Application that will verify if a Contact Exists, and either Update or Add depending on its existence.

 

I am using V3 and am not making an OAUTH2 call, but using the API Key and Secret from the Mashery.

 

Can any please provide me with the GET code? That is the URL and Headers. From there I should be able to work out the rest.

Regards,

Neil

Tags (1)
4 REPLIES 4
Moderator

Re: Console Application V3 Get/UPDATE/ADD Contacts

Hello,

 

When making calls with our V3 API, you need to include an Authorization header that includes an access token obtained through the OAuth flow. The access token is what identifies which Constant Contact account you are making calls for, and whether your application has been granted the necessary permission for the type of call you are making. Your API Key and Secret are only used in the OAuth flow, and when making subsequent calls, your API Key is identified from the access token used in your regular API calls.

 

The URL you would call would be:

https://api.cc.email/v3/contacts?email={email_address}

The headers you would use would be:

Content-Type: application/json
Authorization: Bearer {access_token}


Please let me know if you have any other questions!

 

Regards,
David B.
Tier II API Support Engineer

 

 

Occasional Contributor

Re: Console Application V3 Get/UPDATE/ADD Contacts

Hello David,

Thanks for your reply.

I have tried the following:

xxxxxxxx = the App Secret from the My Applications web page

But is return 401 Unauthorized.

 

        Dim authuri As New Uri("https://api.cc.email/v3/contacts?email={abc@123.com}")

        Dim request As WebRequest = WebRequest.Create(authuri)

        request.Method = "GET"

        request.ContentType = "application/json"

        request.Headers.Add("Authorization", "Bearer {xxxxxxxx}")

        Dim response = request.GetResponse().GetResponseStream()

        Dim reader As New StreamReader(response)

        Dim res As String = reader.ReadToEnd()

        reader.Close()

        response.Close()

 

 

What am I doing wrong?

Neil

Occasional Contributor

Re: Console Application V3 Get/UPDATE/ADD Contacts

Hello David,

I tried this without success.

Am I right in assuming that I can go to the My Application page, get the Secret from the application and use this in my console application, or do I have to go through OAURTH2 every time I execute the application?

I have been trying to get a full example for a console application from OAUTH2 through to retrieving Contact data, but it seems no one has anything that works.

 

Here is my code, in which xxxxxx is the secret from My Application page:

 

        Dim client = New RestClient("https://api.cc.email/v3/contacts?email={ntest3@abc.com}")

        Dim request = New RestRequest(Method.GET)

        request.AddHeader("Content-Type", "application/json")

        request.AddHeader("Host", "idfed.constantcontact.com")

        request.AddHeader("Authorization", "Basic xxxxxx")

        Dim response As IRestResponse = client.Execute(request)

 

Regards,

Neil

Moderator

Re: Console Application V3 Get/UPDATE/ADD Contacts

Hello Neil,

 

The access token you receive during OAuth is the Bearer token you use for making calls to the API. This access token is what tells us which Constant Contact account you are making calls to, as well as the scopes that your app has access to. You would use the Basic authentication of your API Key and Secret during the initial OAuth call, and any refresh call.

 

Once you have gone through the OAuth process initially, you will receive a refresh token along with your access token. The refresh token can be used to obtain a new access token (see: https://v3.developer.constantcontact.com/api_guide/server_flow.html#step-5-refresh-the-access-token) as the access token will expire after 1 hour of non-use up to a maximum of 24 hours. Depending on how often you will be making calls, you may consider building the refresh flow linked above into your application to get the new access token and refresh token before making your calls.


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

 

Regards,
David B.
Tier II API Support Engineer