Update email campaign

Regular Participant

Update email campaign

<?php

$UN = "";
$PW = "";
$Key ="93157487-9583-4dc7-a6d2-719fe0326cc7";
//$title=$_POST["title"];
//$date=$_POST["date"];
//$url=$_POST["url"];
//$html = $_POST["htmlContent"];

//$html= str_replace("<", "&lt;", $html);
//$html= str_replace(">", "&gt;", $html);
//$html= str_replace('"', "'", $html);

$entry ='<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="http://api.constantcontact.com/ws/customers/rareparts/campaigns/1107003996723" rel="edit" />
  <id>http://api.constantcontact.com/ws/customers/rareparts/campaigns/1107003996723</id>
  <title type="text">title</title>
  <updated>2009-10-19T19:36:12.622Z</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/rareparts/campaigns/1107003996723">
      <Name>60th NL</Name>
      <Status>Draft</Status>
      <Date>2009-10-19T19:36:12.622Z</Date>
      <Subject>test 123</Subject>
      <FromName>anupriya@vijaysoftware.com</FromName>
      <ViewAsWebpage>NO</ViewAsWebpage>
      <ViewAsWebpageLinkText></ViewAsWebpageLinkText>
      <ViewAsWebpageText></ViewAsWebpageText>
      <PermissionReminder>YES</PermissionReminder>
      <PermissionReminderText>Youre receiving this email because of your relationship with ctct.
Please &lt;ConfirmOptin>&lt;a style="color:#0000ff;">confirm&lt;/a>&lt;/ConfirmOptin>
your continued interest in receiving email from us.</PermissionReminderText>
      <GreetingSalutation>Dear</GreetingSalutation>
      <GreetingName>FirstName</GreetingName>
      <GreetingString>Greetings!</GreetingString>
      <OrganizationName>ctct</OrganizationName>
      <OrganizationAddress1>123 wsw st</OrganizationAddress1>
      <OrganizationAddress2></OrganizationAddress2>
      <OrganizationAddress3></OrganizationAddress3>
      <OrganizationCity>Ashland</OrganizationCity>
      <OrganizationState>MA</OrganizationState>
      <OrganizationInternationalState></OrganizationInternationalState>
      <OrganizationCountry>us</OrganizationCountry>
      <OrganizationPostalCode>32423</OrganizationPostalCode>
      <IncludeForwardEmail>NO</IncludeForwardEmail>
      <ForwardEmailLinkText></ForwardEmailLinkText>
      <IncludeSubscribeLink>NO</IncludeSubscribeLink>
      <SubscribeLinkText></SubscribeLinkText>
      <EmailContentFormat>HTML</EmailContentFormat>
      <EmailContent>test</EmailContent>
      <EmailTextContent>&lt;Text>This is the text version.&lt;/Text></EmailTextContent>
      <StyleSheet></StyleSheet>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/rareparts/lists/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/rareparts/lists/1" rel="self" />
        </ContactList>
      </ContactLists>
      <FromEmail>
        <Email id="http://api.constantcontact.com/ws/customers/rareparts/settings/emailaddresses/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/rareparts/settings/emailaddresses/1"
          rel="self" />
        </Email>
        <EmailAddress>anupriya@vijaysoftware.com</EmailAddress>
      </FromEmail>
      <ReplyToEmail>
        <Email id="http://api.constantcontact.com/ws/customers/rareparts/settings/emailaddresses/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/rareparts/settings/emailaddresses/1"
          rel="self" />
        </Email>
        <EmailAddress>anupriya@vijaysoftware.com</EmailAddress>
      </ReplyToEmail>
    </Campaign>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/rareparts/campaigns</id>
    <title type="text">Campaigns for customer: rareparts</title>
    <link href="campaigns" />
    <link href="campaigns" rel="self" />
    <author>
      <name>rareparts</name>
    </author>
    <updated>2009-10-19T19:36:12.622Z</updated>
  </source>
</entry>';


     $request ="https://api.constantcontact.com/ws/customers/rareparts/campaigns/1107003996723";
            $session = curl_init($request);

           /// Set up digest authentication

            $userNamePassword = $Key . '%' . $UN . ':' . $PW ;
            // Set cURL options
            curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
            //curl_setopt($session, CURLOPT_POST, 1);
            curl_setopt($session, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($session, CURLOPT_POSTFIELDS, $entry);
            curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
            curl_setopt($session, CURLOPT_HEADER, false); // Do not return headers
            curl_setopt($session, CURLOPT_RETURNTRANSFER, 0);
                   
           
            // Execute cURL session and close it
            $response = curl_exec($session);
            $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);
           curl_close($session);
 
?>

 

It returned as Error 400: Invalid Content.

 

Pls help us

I am waiting for your reply.

Pls as soon as possible.Pls......

1 REPLY 1
Employee

Hey Anupriya,

 

I belive that your error is coming from where you specifiy the content of your email.

 

<EmailContent>test</EmailContent>

The data that you enter here needs to be valid HTML.  Also please make sure that you are putting this information to the proper URI with the correct Campaign ID.

 

Please let me know this helps,

Ryan Davis
Quality Engineer
Developer Portal

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

Visit Page