- Constant Contact Community
- :
- Developer Community
- :
- Developer Support – ask questions, find answers
- :
- Creating Campaign using JAVA giving : Response st...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-19-2012 11:04 AM
Hi All,
I am getting the Error : 400 bad request , while creating a sample campaign using Java Client of CTCTRest API. Is it some thing emailaddress settings needs to be done or XML request problem ?
XML Used :
----------------
<?xml version='1.0'encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/shipcarsnow1/campaigns"rel="edit"/>
<id>http://api.constantcontact.com/ws/customers/shipca
<title type="text">ShipCarsNow Sample Campaign</title>
<updated>2009-10-19T18:34:53.105Z</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/shipca
<Name>ShipCarsNow Sample Campaign</Name>
<Status>Draft</Status>
<Date>2009-10-19T18:34:53.105Z</Date>
<Subject>We'd like your feedback about ShipCarsNow</Subject>
<FromName>ShipCarsNow Test</FromName>
<ViewAsWebpage>YES</ViewAsWebpage>
<ViewAsWebpageLinkText>Click here</ViewAsWebpageLinkText>
<ViewAsWebpageText>Having trouble viewing this email?</ViewAsWebpageText>
<PermissionReminder>NO</PermissionReminder>
<PermissionReminderText></PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstName</GreetingName>
<GreetingString>Greetings!</GreetingString>
<OrganizationName>ShipCarsNow</OrganizationName>
<OrganizationAddress1>Mail Stop 0430</OrganizationAddress1>
<OrganizationAddress2></OrganizationAddress2>
<OrganizationAddress3></OrganizationAddress3>
<OrganizationCity>Omaha</OrganizationCity>
<OrganizationState>NE</OrganizationState>
<OrganizationInternationalState></OrganizationInternationalState>
<OrganizationCountry>US</OrganizationCountry>
<OrganizationPostalCode>68102</OrganizationPostalCode>
<IncludeForwardEmail>NO</IncludeForwardEmail>
<ForwardEmailLinkText></ForwardEmailLinkText>
<IncludeSubscribeLink>NO</IncludeSubscribeLink>
<SubscribeLinkText></SubscribeLinkText>
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent><html lang="en" xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:cctd="http://www.constantcontact.com/cctd">
<body><CopyRight>Copyright (c) 1996-2009 Constant Contact.
All rights reserved. Except as permitted under a
separate
written agreement with Constant Contact, neither the Constant Contact
software, nor any content that appears on any
Constant Contact site,
including but not limited to, web pages, newsletters, or templates may be
reproduced, republished, repurposed, or
distributed without the
prior written permission of Constant Contact. For inquiries regarding
reproduction or distribution of any Constant
Contact material, please
contact rdevapa@upcontractor.up.com.</CopyRight>
<OpenTracking/>
<!-- Do NOT delete previous line if you want to get statistics on the
number of opened emails -->
<CustomBlock name="letter.intro" title="Personalization">
<Greeting/>
</CustomBlock>
</body>
</html>
</EmailContent>
<EmailTextContent><Text>This is the text version.</Text></EmailTextContent>
<StyleSheet></StyleSheet>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/lists/170" rel="self"/>
</ContactList></ContactLists>
<FromEmail>
<Email id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailaddresse
</Email>
<EmailAddress>rdevapa@upcontractor.up.com</EmailAddress>
</FromEmail>
<ReplyToEmail>
<Email id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailaddresse
</Email>
<EmailAddress>rdevapa@upcontractor.up.com</EmailAddress>
</ReplyToEmail>
</Campaign>
</content>
<source>
<id>http://api.constantcontact.com/ws/customers/shipca
<title type="text">Campaigns for customer: Shipcarsnow1</title>
<link href="campaigns"/>
<link href="campaigns"rel="self"/>
<author>
<name>shipcarsnow1</name>
</author>
<updated>2009-10-19T18:34:53.105Z</updated>
</source>
</entry>
================================
JAVA Code Snippet :
================
HttpPost httppost =newHttpPost("https://api.constantcontact.com/ws/customers/shipc
httppost.addHeader("Content-Type", "application/atom+xml");
ByteArrayEntity entity = newByteArrayEntity(xmlRequest.getBytes());
httppost.setEntity(entity);
HttpResponse response = getAuthenticatedConnection().execute(httppost);
System.out.println("Response status :"+response.getStatusLine());
InputStreamReader r = newInputStreamReader(response.getEntity().getContent(
=============
public DefaultHttpClient getAuthenticatedConnection() throwsClientProtocolException, IOException {
SchemeRegistry schemeRegistry = newSchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
org.apache.http.params.HttpParams params = newBasicHttpParams();
ThreadSafeClientConnManager cm = newThreadSafeClientConnManager(params, schemeRegistry);
httpclient = newDefaultHttpClient(cm, params);
String loginUsername = (new StringBuilder(String.valueOf(API_KEY))).append("%").append(username).toString();
httpclient.getCredentialsProvider().setCredentials(AuthScope
StringBuilder stringBuilder = new StringBuilder("https://api.constantcontact.com/ws/customers/");
stringBuilder.append(username).append("/");
System.out.println(stringBuilder.toString());
InputStream stream = doGetRequest(stringBuilder.toString());
if(stream != null){
System.out.println("Autt User");
}
else{
System.out.println("Not Autt User");
}
returnhttpclient;
}
Solved! Go to Solution.
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-19-2012 03:18 PM
Hi,
On lines 3 and 90 you are missing a space between rel and the quote before it. For example on Line 3, this code
<link href="/ws/customers/shipcarsnow1/campaigns"rel="edit"/>
should be this:
<link href="/ws/customers/shipcarsnow1/campaigns" rel="edit"/>
Likewise, on Line 90, this:
<link href="campaigns"rel="self"/>
should be this.
<link href="campaigns" rel="self"/>
Regards,
Support Engineer, Constant Contact
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-19-2012 03:32 PM
Richard,
Its missed while copy paste the xml from Eclipse, space is there in XML, did u find any other problem with xml ?
My doubt is do we need to do any thing with settings and what is the significance of the folloowing line ?
I have created a sample list 170, added some emilids to that list , apart from that I haven't done any settings/emailaddress like : "/ws/customers/shipcarsnow1/settings/emailaddresse
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/lists/170" rel="self"/>
</ContactList>
</ContactLists>
<FromEmail>
<Email id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns=http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailaddresse
</Email>
<EmailAddress>rdevapa@upcontractor.up.com</EmailAddress>
</FromEmail>
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-19-2012 06:11 PM
The rdevapa@upcontractor.up.com address is not a verified address in your account. Our system will return a 400 error if you try to specify a from address that is not verified. You can get the address numbers and the address of each verified contact from the following URL:
https://api.constantcontact.com/ws/customers/shipc
Just visit that URL and enter in your API key, followed by a percent sign and your user name in the user name box. Then, enter your password in the password box. Then, you can view the XML by viewing the source for the page. The correct number of the contacts is shown in the id node.
Also, on Line 11 of your XML, there is an extra space. This:
<Campaign xmlns="http://ws.constantcontact.com/ns/1.0/ "
should be this:
<Campaign xmlns="http://ws.constantcontact.com/ns/1.0/"
I was able to successfully create a campaign using your XML after correcting the above issues
Support Engineer, Constant Contact
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-20-2012 11:05 AM
I have corrected those email still getting bad request : here is XML copied from Test Editor:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/shipcarsnow1/campaigns" rel="edit"/>
<id>http://api.constantcontact.com/ws/customers/shipca
</id>
<title type="text">API Test Email</title>
<updated>2009-10-19T18:34:53.105Z</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/shipca
<Name>API Test Email</Name>
<Status>Draft</Status>
<Date>2009-10-19T18:34:53.105Z</Date>
<Subject>ShipCarsNow Test</Subject>
<FromName>ShipCarsNow Test</FromName>
<ViewAsWebpage>NO</ViewAsWebpage>
<ViewAsWebpageLinkText/>
<ViewAsWebpageText/>
<PermissionReminder>YES</PermissionReminder>
<PermissionReminderText>
You're receiving this email because of your relationship with ctct.
Please
<ConfirmOptin>
<a style="color:#0000ff;">confirm</a>
</ConfirmOptin>
your continued interest in receiving email from us.
</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstName</GreetingName>
<GreetingString>Greetings!</GreetingString>
<OrganizationName>ShipCarsnow</OrganizationName>
<OrganizationAddress1>123 wsw st</OrganizationAddress1>
<OrganizationAddress2/>
<OrganizationAddress3/>
<OrganizationCity>OMAHA</OrganizationCity>
<OrganizationState>NE</OrganizationState>
<OrganizationInternationalState/>
<OrganizationCountry>US</OrganizationCountry>
<OrganizationPostalCode>32423</OrganizationPostalC
<IncludeForwardEmail>NO</IncludeForwardEmail>
<ForwardEmailLinkText/>
<IncludeSubscribeLink>NO</IncludeSubscribeLink>
<SubscribeLinkText/>
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:cctd="http://www.constantcontact.com/cctd">
<body>
<CopyRight>Copyright (c) 1996-2009 Constant Contact. All rights
reserved. Except as permitted under a separate written agreement
with Constant Contact, neither the Constant Contact software, nor
any content that appears on any Constant Contact site, including
but not limited to, web pages, newsletters, or templates may be
reproduced, republished, repurposed, or distributed without the
prior written permission of Constant Contact. For inquiries
regarding reproduction or distribution of any Constant Contact
material, please contact slboucher@shipcarsnow.com.
</CopyRight>
<OpenTracking/>
<!-- Do NOT delete previous line if you want to get statistics on the
number of opened emails -->
<CustomBlock name="letter.intro" title="Personalization">
<Greeting/>
</CustomBlock>
</body>
</html>
</EmailContent>
<EmailTextContent>
<Text>This is the text version.</Text>
</EmailTextContent>
<StyleSheet/>
<ContactLists>
<ContactList
id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/lists/170"
rel="self"/>
</ContactList>
</ContactLists>
<FromEmail>
id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom"
href="/ws/customers/shipcarsnow1/settings/emailaddresses/8" rel="self"/>
</Email>
<EmailAddress>slboucher@shipcarsnow.com</EmailAddress>
</FromEmail>
<ReplyToEmail>
id="http://api.constantcontact.com/ws/customers/shipca
<link xmlns="http://www.w3.org/2005/Atom"
href="/ws/customers/shipcarsnow1/settings/emailaddresses/8" rel="self"/>
</Email>
<EmailAddress>slboucher@shipcarsnow.com</EmailAddress>
</ReplyToEmail>
</Campaign>
</content>
<source>
<id>http://api.constantcontact.com/ws/customers/shipca
</id>
<title type="text">Campaigns for customer: shipcarsnow1</title>
<link href="campaigns"/>
<link href="campaigns" rel="self"/>
<author>
<name>shipcarsnow1</name>
</author>
<updated>2009-10-19T19:36:12.622Z</updated>
</source>
</entry>
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-20-2012 02:03 PM
The XML content posted above is different from the original XML. I found these errors in the new XML:
- The </id> closing tag needs to be on the same line as <id>.
- The left-angle brackets inside PermissionReminderText, EmailContent, and EmailTextContent need to be converted to< enttites.
So, here is how the new XML should look:
<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom"> <link href="/ws/customers/shipcarsnow1/campaigns" rel="edit"/> <id>http://api.constantcontact.com/ws/customers/shipcarsnow1/campaigns</id> <title type="text">API Test Email</title> <updated>2009-10-19T18:34:53.105Z</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/shipca rsnow1/campaigns/1111122233"> <Name>API Test Email</Name> <Status>Draft</Status> <Date>2009-10-19T18:34:53.105Z</Date> <Subject>ShipCarsNow Test</Subject> <FromName>ShipCarsNow Test</FromName> <ViewAsWebpage>NO</ViewAsWebpage> <ViewAsWebpageLinkText/> <ViewAsWebpageText/> <PermissionReminder>YES</PermissionReminder> <PermissionReminderText> You're receiving this email because of your relationship with ctct. Please <ConfirmOptin> <a style="color:#0000ff;">confirm</a> </ConfirmOptin> your continued interest in receiving email from us. </PermissionReminderText> <GreetingSalutation>Dear</GreetingSalutation> <GreetingName>FirstName</GreetingName> <GreetingString>Greetings!</GreetingString> <OrganizationName>ShipCarsnow</OrganizationName> <OrganizationAddress1>123 wsw st</OrganizationAddress1> <OrganizationAddress2/> <OrganizationAddress3/> <OrganizationCity>OMAHA</OrganizationCity> <OrganizationState>NE</OrganizationState> <OrganizationInternationalState/> <OrganizationCountry>US</OrganizationCountry> <OrganizationPostalCode>32423</OrganizationPostalC ode> <IncludeForwardEmail>NO</IncludeForwardEmail> <ForwardEmailLinkText/> <IncludeSubscribeLink>NO</IncludeSubscribeLink> <SubscribeLinkText/> <EmailContentFormat>HTML</EmailContentFormat> <EmailContent> <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:cctd="http://www.constantcontact.com/cctd"> <body> <CopyRight>Copyright (c) 1996-2009 Constant Contact. All rights reserved. Except as permitted under a separate written agreement with Constant Contact, neither the Constant Contact software, nor any content that appears on any Constant Contact site, including but not limited to, web pages, newsletters, or templates may be reproduced, republished, repurposed, or distributed without the prior written permission of Constant Contact. For inquiries regarding reproduction or distribution of any Constant Contact material, please contact slboucher@shipcarsnow.com. </CopyRight> <OpenTracking/> <!-- Do NOT delete previous line if you want to get statistics on the number of opened emails --> <CustomBlock name="letter.intro" title="Personalization"> <Greeting/> </CustomBlock> </body> </html> </EmailContent> <EmailTextContent> <Text>This is the text version.</Text> </EmailTextContent> <StyleSheet/> <ContactLists> <ContactList id="http://api.constantcontact.com/ws/customers/shipca rsnow1/lists/170"> <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/lists/170" rel="self"/> </ContactList> </ContactLists> <FromEmail> <Email id="http://api.constantcontact.com/ws/customers/shipca rsnow1/settings/emailaddresses/8"> <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailadd resses/8" rel="self"/> </Email> <EmailAddress>slboucher@shipcarsnow.com</EmailAddr ess> </FromEmail> <ReplyToEmail> <Email id="http://api.constantcontact.com/ws/customers/shipca rsnow1/settings/emailaddresses/8"> <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailadd resses/8" rel="self"/> </Email> <EmailAddress>slboucher@shipcarsnow.com</EmailAddr ess> </ReplyToEmail> </Campaign> </content> <source> <id>http://api.constantcontact.com/ws/customers/shipca rsnow1/campaigns </id> <title type="text">Campaigns for customer: shipcarsnow1</title> <link href="campaigns"/> <link href="campaigns" rel="self"/> <author> <name>shipcarsnow1</name> </author> <updated>2009-10-19T19:36:12.622Z</updated> </source> </entry>
Support Engineer, Constant Contact
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-23-2012 10:36 AM
Richard,
I tried with the XML provided by you still am getting the Bad Request error, let me know if its possible to send logs contains any info about my request based, latest time i runned the program is 9:30 AM CST April 23rd 2012.
Also the list which we created has do required any permisiion ? meaning is the following part of xml needs any permission etc and let us do our API_KEY has permission to create campaign ro not our API_KEY :
"1af18f30-b9f3-437d-b37d-8d0bd10f92b5" ?
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/shipcarsnow1/lists/170">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/lists/170" rel="self"/>
</ContactList>
</ContactLists>
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-23-2012 01:48 PM
Hi,
That API key is valid. Usually when you do not have permission to access a certain resource, you will get a 401 error, instead of a 400 one. I would double-check the list number. If you visit https://api.constantcontact.com/ws/customers/shipc
Support Engineer, Constant Contact
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-24-2012 10:26 AM
Richard,
thanks for giving tip about the RestClient, it worked fine , when I extratced existing campign's xml and modified the same to create new campaign was successful.
I want to know is ShipCarsNow account has permision to Schduling and Sending Compaing using out API_KEY ?
Re: Creating Campaign using JAVA giving : Response status :HTTP/1.1 400 Bad Request
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-24-2012 01:52 PM
Hi,
Your API key currently does not have permission to schedule and send. I just e-mailed you some questions about it. Once we get those answered, I can enable your key for scheduling and send you the scheduling documentation.
Thanks,
Support Engineer, Constant Contact


