Updating a list 400 Failed to deserialize your request

I can't find any way around getting a 400 error when I change the name of a list using an xml request through API. The documentation says I need to use a PUT request when sending this to curl. I might add that the list id is matches up to the list I've been trying to update. Any help on this would be greatly appreciated.

      $xml_writer = new XMLWriter();

      $xml_writer->setIndent( TRUE );
      $xml_writer->setIndentString( "    " );
      $xml_writer->startElement( 'List' );
      $xml_writer->startElement( 'ConfirmedOptIn' );
      $xml_writer->writeCData( false );
      $xml_writer->startElement( 'ConfirmationSuccessPage' );
      $xml_writer->writeCData( '' );
      $xml_writer->startElement( 'Title' );
      $xml_writer->writeCData( $name );
      $xml_writer->startElement( 'UnsubscribePage' );
      $xml_writer->writeCData( '' );

      $xml_str = $xml_writer->outputMemory( FALSE );
      $xml_response = $this->process( $this->api_url.'lists/'.$list_id.'.xml', $this->username, $xml_str, "PUT" );

   private function process( $url=FALSE, $username=FALSE, $request=FALSE, $custom_request=FALSE ){
      $ch = curl_init();

      if( $url ){
         curl_setopt( $ch, CURLOPT_URL, $url );
         curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
         curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
         curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 15 );
         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
         if( $custom_request ){
            if( $custom_request === 'PUT' ){
               curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Length: '.strlen( $custom_request ) ) );
            curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $custom_request );
         if( $request ){
            curl_setopt( $ch, CURLOPT_POST, TRUE );
            curl_setopt( $ch, CURLOPT_POSTFIELDS, $request );
            curl_setopt( $ch, CURLOPT_POST, 0 );
         if( $username ){
            curl_setopt( $ch, CURLOPT_USERPWD, $username.':' );
         $response = curl_exec( $ch );
         curl_close( $ch );

         return simplexml_load_string( $response );
         return FALSE;

tobyb tobyb, 6 years ago

Hi Domics,

It looks like your using PHP, have you had a look at the wrapper we've created? If that's not an option for you then get in touch with support at campaignmonitor.com with your account details and we can have a look at the xml your sending.

Join 150,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free