cancel
Showing results for 
Search instead for 
Did you mean: 

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

Occasional Participant

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

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
Honored Contributor

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

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
Occasional Participant

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

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

Honored Contributor

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

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
Participant

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

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.

Honored Contributor

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

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
Participant

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

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.

Participant

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

 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.

Highlighted
Honored Contributor

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

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
Occasional Participant

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

Hi