title: Create new etherpad using PHP and CURL
body: <p>I'm trying to write a simple PHP script which automatically sets up new etherpads (see <a href="http://etherpad.com/" rel="nofollow noreferrer">http://etherpad.com/</a>).</p>
  
  <p>They don't have an API (yet) for creating new pads so I'm trying to figure if I can do things another way.</p>
  
  <p>After playing around some, I found that if you append a random string to etherpad.com to a not-yet-created pad, it'll come back with a form asking if you want to create a new etherpad at that address. If you submit that form, a new pad will be created at that URL.</p>
  
  <p>My thought then was I could just create a PHP script using CURL that would duplicate that form and trick etherpad into creating a new pad at whatever URL I give it. I wrote the script but so far I can't get it working. Can someone tell me what I'm doing wrong?</p>
  
  <p>First, here's the HTML form on the etherpad creation page:</p>
  
  <p>`</p>
  
  <pre><code>&lt;p&gt;&lt;tt id="padurl"&gt;http://etherpad.com/lsdjfsljfa-fdj-lsdf&lt;/tt&gt;&lt;/p&gt;
  
  &lt;br/&gt;
  &lt;p&gt;There is no EtherPad document here. Would you like to create one?&lt;/p&gt;
  
  &lt;input type="hidden" value="lsdjfsljfa-fdj-lsdf" name="padId"/&gt;
  &lt;input type="submit" value="Create Pad" id="createPad"/&gt;
  </code></pre>
  
  <p>
  `</p>
  
  <p>Then here's my code which tries to submit the form using CURL</p>
  
  <pre><code>$ch = curl_init();
  
  //set POST variables
  $url = "http://etherpad.com/ep/pad/create?padId=ldjfal-djfa-ldkfjal";
  $fields = array(
    'padId'=&gt;urlencode("ldjfal-djfa-ldkfjal"),
  );
  
  $useragent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)";  
  
  // set user agent  
  curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
  
  //url-ify the data for the POST
  foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value; }
  print_r($fields_string);
  
  //open connection
  $ch = curl_init();
  
  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_POST,count($fields));
  curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  
  //execute post
  $result = curl_exec($ch);
  print_r($result);
  //close connection
  curl_close($ch);
  </code></pre>
  
  <p>When I run the script, PHP reports back that everything executed correctly but etherpad doesn't create my pad. Any clues what's going on?</p>