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->openMemory();
      $xml_writer->setIndent( TRUE );
      $xml_writer->setIndentString( "    " );
      $xml_writer->startElement( 'List' );
      $xml_writer->startElement( 'ConfirmedOptIn' );
      $xml_writer->writeCData( false );
      $xml_writer->endElement();
      $xml_writer->startElement( 'ConfirmationSuccessPage' );
      $xml_writer->writeCData( '' );
      $xml_writer->endElement();
      $xml_writer->startElement( 'Title' );
      $xml_writer->writeCData( $name );
      $xml_writer->endElement();
      $xml_writer->startElement( 'UnsubscribePage' );
      $xml_writer->writeCData( '' );
      $xml_writer->endElement();
      $xml_writer->endElement();

      $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 );
         }else{
            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 );
      }else{
         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.

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free