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/shipcarsnow1/campaigns</id> <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/shipcarsnow1/1111122222333"> <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/shipcarsnow1/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/shipcarsnow1/settings/emailaddresses/170"> <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailaddresses/170" rel="self"/> </Email> <EmailAddress>rdevapa@upcontractor.up.com</EmailAddress> </FromEmail> <ReplyToEmail> <Email id="http://api.constantcontact.com/ws/customers/shipcarsnow1/settings/emailaddresses/170"> <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/shipcarsnow1/settings/emailaddresses/170" rel="self"/> </Email> <EmailAddress>rdevapa@upcontractor.up.com</EmailAddress> </ReplyToEmail> </Campaign> </content> <source> <id>http://api.constantcontact.com/ws/customers/shipcarsnow1/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-19T18:34:53.105Z</updated> </source> </entry> ================================ JAVA Code Snippet : ================ HttpPost httppost =newHttpPost("https://api.constantcontact.com/ws/customers/shipcarsnow1/campaigns"); 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.ANY, new UsernamePasswordCredentials(loginUsername, password)); 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; }
... View more