title: "Version Mismatch" error using SOAP and php to connect to API
body: <p>I am trying to write some code to connect a webpage to an external API. The API's documentation tells me that the request should be done with a SOAP envelope, which should look like this:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema"&gt;
  &lt;soap:Body&gt;
    &lt;GetNote&gt;
      &lt;Request&gt;
        &lt;Security&gt;
          &lt;Username&gt;username&lt;/Username&gt;
          &lt;Password&gt;password&lt;/Password&gt;
        &lt;/Security&gt;
        &lt;NoteID&gt;noteID&lt;/NoteID&gt;
      &lt;/Request&gt;
    &lt;/GetNote&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Using some sample code created by a helpful StackOverflow user here: <a href="https://stackoverflow.com/questions/7120586/soap-request-in-php-with-curl">SOAP request in PHP with CURL</a> I then turned it into this (slightly redacted) php:</p>
  
  <pre><code>&lt;?php
  $soapUrl = 'https://www.blah.com/DoodadService.cfc?wsdl';
  $xml_post_string = '&lt;soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema"&gt;
  &lt;soap:Body&gt;
    &lt;GetNote&gt;
      &lt;Request&gt;
        &lt;Security&gt;
          &lt;Username&gt;'.$soapUser.'&lt;/Username&gt;
          &lt;Password&gt;'.$soapPassword.'&lt;/Password&gt;
        &lt;/Security&gt;
        &lt;NoteID&gt;'.$soapNoteID.'&lt;/NoteID&gt;
      &lt;/Request&gt;
    &lt;/GetNote&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;';
  
  $headers = array(
                          "Content-type: text/xml;charset=\"utf-8\"",
                          "Accept: text/xml",
                          "Cache-Control: no-cache",
                          "Pragma: no-cache",
                          "SOAPAction: https://www.blah.com/DoodadService.cfc?wsdl",
                          "Content-length: ".strlen($xml_post_string),
                      );
  
  $url = $soapUrl;
  
  
  $ch = curl_init();
  echo('set curl&lt;br&gt;');
  $f = fopen('request.txt','w');
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_VERBOSE,true);
  curl_setopt($ch, CURLOPT_STDERR, $f);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  echo('about to execute&lt;br&gt;');
  // converting
  $response = curl_exec($ch);
  fclose($f);
  echo('Got '.strlen($response).' characters in response&lt;br&gt;');
  curl_close($ch);
  echo('Saved error strings to request.txt&lt;br&gt; ');
  ?&gt;
  </code></pre>
  
  <p>The result was a Version Mismatch error, ie:</p>
  
  <pre><code>&lt;soapenv:Fault&gt;
  &lt;faultcode&gt;
  soapenv:VersionMismatch&lt;/faultcode&gt;
  &lt;faultstring&gt;
  Version Mismatch&lt;/faultstring&gt;
  &lt;detail&gt;
  &lt;ns1:hostname xmlns:ns1="http://xml.apache.org/axis/"&gt;
  ip-10-4-4-149&lt;/ns1:hostname&gt;
  &lt;/detail&gt;
  &lt;/soapenv:Fault&gt;
  </code></pre>
  
  <p>Can anyone tell me what this error means, what is being "mismatched" against what, and how I might be able to fix it up?</p>
  
  <p>Thanks!</p>