Contact list not showing when retrieving campaign details using ws API.

Regular Participant

Contact list not showing when retrieving campaign details using ws API.

Hi,

 

Campaign details retieved using the following API uri is not listing the contactlist associated with the campaign.

FYI:The account used for testing is in expired state.

https://api.constantcontact.com/ws/customers/twbsind%40gmail.com/campaigns/1124895671653

 

Response from the api is given below:

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/twbsind%40gmail.com/campaigns/1124895671653" rel="edit"/>
  <id>http://api.constantcontact.com/ws/customers/twbsind%40gmail.com/campaigns/1124895671653</id>
  <title type="text">Jithin Campaign</title>
  <updated>2016-06-03T09:05:38.513Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <content type="application/vnd.ctct+xml">
    <Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/twbsind%40gmail.com/campaigns/1124895671653">
      <Name>Jithin Campaign</Name>
      <Status>Sent</Status>
      <Date>2016-06-03T09:05:38.513Z</Date>
      <LastEditDate>2016-06-22T11:58:14.383Z</LastEditDate>
      <LastRunDate>2016-06-03T09:05:38.509Z</LastRunDate>
      <Sent>1</Sent>
      <Opens>0</Opens>
      <Clicks>0</Clicks>
      <Bounces>0</Bounces>
      <Forwards>0</Forwards>
      <OptOuts>0</OptOuts>
      <SpamReports>0</SpamReports>
      <SharePageURL>http://myemail.constantcontact.com/-enter-subject-here-.html?soid=1124448820800&amp;aid=99SEhECL4Z4</SharePageURL>
      <Subject>Test for Campaing list</Subject>
      <FromName>Jithin</FromName>
      <CampaignType>TEMPLATE_V2</CampaignType>
      <ViewAsWebpage>NO</ViewAsWebpage>
      <ViewAsWebpageLinkText></ViewAsWebpageLinkText>
      <ViewAsWebpageText></ViewAsWebpageText>
      <PermissionReminder>NO</PermissionReminder>
      <PermissionReminderText></PermissionReminderText>
      <GreetingSalutation></GreetingSalutation>
      <GreetingString></GreetingString>
      <OrganizationName>TW</OrganizationName>
      <OrganizationAddress1>ABC</OrganizationAddress1>
      <OrganizationAddress2>DEF</OrganizationAddress2>
      <OrganizationAddress3>GHI</OrganizationAddress3>
      <OrganizationCity>AZ</OrganizationCity>
      <OrganizationState>nj</OrganizationState>
      <OrganizationInternationalState></OrganizationInternationalState>
      <OrganizationCountry>us</OrganizationCountry>
      <OrganizationPostalCode>07747</OrganizationPostalCode>
      <IncludeForwardEmail>NO</IncludeForwardEmail>
      <ForwardEmailLinkText></ForwardEmailLinkText>
      <IncludeSubscribeLink>NO</IncludeSubscribeLink>
      <SubscribeLinkText></SubscribeLinkText>
      <ArchiveStatus></ArchiveStatus>
      <ArchiveURL></ArchiveURL>
      <FromEmail>
        <Email id="http://api.constantcontact.com/ws/customers/twbsind%40gmail.com/settings/emailaddresses/0">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/twbsind%40gmail.com/settings/emailaddresses/0" rel="self"/>
        </Email>
        <EmailAddress></EmailAddress>
      </FromEmail>
      <ReplyToEmail>
        <Email id="http://api.constantcontact.com/ws/customers/twbsind%40gmail.com/settings/emailaddresses/0">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/twbsind%40gmail.com/settings/emailaddresses/0" rel="self"/>
        </Email>
        <EmailAddress></EmailAddress>
      </ReplyToEmail>
      <Date>2016-06-03T09:02:23.518Z</Date>
      <LastEditDate>2016-06-03T09:05:38.513Z</LastEditDate>
      <LastRunDate>2016-06-03T09:05:38.509Z</LastRunDate>
      <GreetingName>NONE</GreetingName>
      <ProductID>1</ProductID>
      <ShowAgent>true</ShowAgent>
    </Campaign>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/twbsind%40gmail.com/campaigns</id>
    <title type="text">Campaigns for customer: twbsind@gmail.com</title>
    <link href="campaigns"/>
    <link href="campaigns" rel="self"/>
    <author>
      <name>twbsind@gmail.com</name>
    </author>
    <updated>2016-06-22T11:58:14.790Z</updated>
  </source>
</entry>

 

Please advice what is  missing and how to proceeed .

 

Thanks & Regards

RN

34 REPLIES 34
Member

Hello,

 

After digging into this a bit, it appears the problem is a compatibility issue between the V1 (/ws) API and the structure of emails created with our new 3rd generation editor (3GE). This is not an issue with our newer V2 API, and switching to using the V2 API is definitely the suggested solution to this problem. Is there a specific reason that you chose to work with our V1 API rather than the newer V2 API?

 

As a side note, I do want to mention that the V1 API is in a deprecated state and currently only receives fixes for security issues and the most critical bugs. I would strongly suggest against starting new development on the V1 API.

 

Sincerely,

Elijah G.
API Support Engineer
Regular Participant

Constantcontact API had implemented  some 5-6 years ago  with the ws (V1) version which was the one available at that time and was working without issues through these years. We will  try with new  V2 API as suggested.

 

Thanks for the reply.

 

Thanks

RN.

Regular Participant

Hi,

 

Thanks for your help. But if I give the url as 'http://developer.constantcontact.com/docs/email-campaigns/email-campaigns-collection.html , we can get the result as given below.

 

  1. "id": "1100395494220",
  2. "name": "1357157252225",
  3. "status": "SENT",
  4. "modified_date": "2013-01-07T18:51:35.975Z"

But we need the campaign details, same as the xml that we posted in the question and also we need contact list in that xml. Please le me know your reply.

Hello,

 

In order to get the information you want, you'll want to use the individual campaign endpoint, for which you can find the documentation here: http://developer.constantcontact.com/docs/email-campaigns/email-campaign-resource.html

 

For the sample in your post, you would make a GET call to https://api.constantcontact.com/v2/emailmarketing/campaigns/1100395494220.

 

This data will include the contact list as well as other campaign details that you will need. If you have any questions, please let me know!

 

Sincerely

Elijah G.
API Support Engineer
Regular Participant

Hi,

 

I got an another issue on  HttpWebResponse response = request.GetResponse() as HttpWebResponse;  code.

 

I am working V1 version. But after updating to v2 I changed the URL as  https://api.constantcontact.com/v2/emailmarketing/campaigns/1100395494220. But When the issued code reached it throw an excetpion. The excepetion is "The remote server returned an error: (403) Forbidden.". 

 

I am using V1API Code. is that the issue? If that, how to upgrade the V1API code to V2API code. Please let me know the procedure.

Regular Participant

 

Hi,

 

We are using username,pasword to get the Campaign details. When I checked the authentication it look different. Is we can use same procedure for V2, for getting the Campaign details?

Hello,

 

There are likely two components to the issue you're seeing:

  1. You need a V2 API key to use the V2 API
  2. You need an Access Token instead of basic(user/pass) authentication.

 

You can resolve both of those by following the first three steps here: https://constantcontact.mashery.com/

 

Once you have both, you will need to append the api key as a query parameter, so that https://api.constantcontact.com/v2/emailmarketing/campaigns/1100395494220 becomes https://api.constantcontact.com/v2/emailmarketing/campaigns/1100395494220?api_key=APIKEY.

 

Next you'll need to send a different authorization header instead of the username/password. the format of the header is:

Authorization: Bearer ACCESS_TOKEN

 

Once you have both the new API key and a token, you should be able to successfully make API calls.

 

Sincerely,

Elijah G.
API Support Engineer
Regular Participant

Hi,

 

Thanks for the help. As per your reply, I have registered the Addon in Contant contact mashery account. After registration,I got the API key and token. But when I search for getting Campaign details using a campaign id using your seach window I am getting an error. I am attaching the screen shot with this mail. Please help me on this.

Hello,

 

Based on your screenshot (Which I've removed to protect your information) and my own testing, it looks like the problem is that you've got an extra space in front of your token that's messing up the auth header. If you remove that space, it should start working as expected!

 

Sincerely,

Elijah G.
API Support Engineer
Regular Participant

Jithin George - Outlook Web App

Hi,
Thank you for your help. Now I am able to get the campaign details. But I have 2 more issues regarding this.
 
1) The campaign details is in 'json' format. But we need details in xml format. The code we implemented to get the Campaign details as xml is given below.


HttpWebResponse response = request.GetResponse() as HttpWebResponse;

using (response)

{

StreamReader reader = new StreamReader(response.GetResponseStream());

XmlDocument doc = new XmlDocument();

doc.Load(reader);

}
Can you please tell me, is there any way to get details in xml format. Because if we change the format as json format, we need to change logic in lots of areas.

2) When I search the campaign using the campaign id in your search window it gives all campaign details. But when I looked in to the details, Contact list id is shown in contact list. Please check the screen shot below. We need contact list name also along id.
 
Can you help me on this.

2016-07-07_182817.jpg

Hello,

 

Here's some information related to your 2 issues:

 

  1. The V2 API is JSON only. The only API that outputs XML is out V1 API which is deprecated and we will be announcing the end-of-life date for it in the near future. However, if you are working in .NET, you can convert the JSON to XML using this framework: http://www.newtonsoft.com/json/help/html/convertingjsonandxml.htm#ID3RBSection

  2. In order to get the list names, you will need to do one of two things:
    1. make a GET API call to /v2/lists/LISTID for each list
      or
    2. make a GET API call to /v2/lists to get all lists, and search the collection in your code to find the list names.

If you have any questions for me, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Regular Participant

Hi,

 

Thanks for your help and valuable information. Now it works fine. But there is a question regarding authentication. I can access Token from UI (Mashery account). But in my product , is there any hope to get Token from internally means using code. Its an urgent question.Please help me on this

Hello,

 

Great to hear that things are working!

 

It is possible to get tokens directly by implementing OAuth 2.0 in your code. You can see this demonstrated by our two sample apps that are included with the .NET SDK. You can find those here: https://github.com/constantcontact/.net-sdk. You can also read about implementing OAuth 2.0 here: http://developer.constantcontact.com/docs/authentication/authentication.html

 

This is a bit of a complex topic, so please feel free to reach out with questions you have!

 

Sincerely,

 

 

Elijah G.
API Support Engineer
Regular Participant

Hi..

 

Thanks for your reply. I need a little help. When I tried to authenticate using this code I got an exeption.The code is given below.

 

string state = "**********";

Token = OAuth.AuthenticateFromWinProgram(ref state);

 

I thought here the state means username. After I give this I got that exception that i early mention that.

 

But I think its not the issue after I gave username as 'state'. The issue is-

 

ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.

 

Please help me on this.

Hello,

 

Based on that error message, it seems like this exact method may not work best for you, as it seems that you may be working with a web application rather than a desktop/winforms application. For working with a web application, here's how I built an OAuth tester.

 

Default.aspx:

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
            <a href="?getToken=true">Get a Token!</a>
            Your Token is: <asp:Label ID="tokenholder" runat="server"/>      
</asp:Content>

Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CTCT.Authentication.WebPage;

namespace WebApplication2
{
    public partial class _Default : Page
    {
        protected string token="empty";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Request.QueryString["getToken"] != null)
            {
                var authPage = new AuthenticationWebPage(HttpContext.Current, "");
                authPage.GetAuthorizationCode();
            }
            else if (HttpContext.Current.Request.QueryString["code"] != null)
            {
                var authPage = new AuthenticationWebPage(HttpContext.Current, "");
                token = authPage.GetAccessTokenByCode(HttpContext.Current.Request.QueryString["code"]);
            }
            tokenholder.Text = token;
        }
    }
}

Add the following to your web.config, filling in the values:

  <appSettings>
    <add key="APIKey" value="YOUR_API_KEY" />
    <add key="RedirectURL" value="YOUR_REDIRECT_URL" />
    <add key="ClientSecretKey" value="YOUR_API_KEY_SECRET" />
  </appSettings>

For the purposes of testing, you will want to configure your redirect URL to point at the default.aspx page. Please note that the Redirect URL in your config, and the redirect URL configured on your API key must match. You can edit your API key to set the Redirect URL here: https://constantcontact.mashery.com/apps/myapps

 

If you have any difficulty with this, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Regular Participant

Hi,

 

Sorry Elijah. We are using windows application not web application.

 

Here I had tested some code for getting token. But I couldn't get that.

 

string JTestReqURL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?response_type=token&client_id=ez...";
Uri JTestaddress = new Uri(JTestReqURL);
HttpWebRequest JTestrequest = WebRequest.Create(JTestaddress) as HttpWebRequest;
using (HttpWebResponse response = JTestrequest.GetResponse() as HttpWebResponse)
{
  StreamReader reader = new StreamReader(response.GetResponseStream());
  string xml = reader.ReadToEnd();
}

 

Can u please help me on this. Is we can get token using thes codes.

Regular Participant

 Hi Elijah_G,

 

That works.I mean I can access authentication form. But still I have an issue, I have to give 'RedirectURL' for accessing the token. Can you please help me on this. What should I give for that field.

Hello,

 

By default, the Redirect URL for any API key is http://localhost. In your case, since it will be a windows application, it is fine to keep that as the redirect URL. If you have any issues with this URL, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Regular Participant

Hi 

 

 

Regular Participant

Hi,

 

Thanks for ur valuable help. I need alittle help from you. In previous version I can get optouts in retriving xml. But now I couldn't get that field. Can you please help me on this.

Developer Portal

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

Visit Page