Advertisement
freephile

SubversionEdge REST API doesn't work

May 8th, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2. // set up the URL value involved in a variable
  3. $url = "http://code.example.com:3343/csvn/api/1/user?format=json";
  4. // administrative user for API access
  5. $username = 'grundlett';
  6. $password = 'secret-words';
  7.  
  8. // set up the data that is going to be passed
  9. $data = array(
  10.   array(
  11.     "username" => "example1",
  12.     "password" => "mysecret",
  13.     "fullName" => "Example Uno",
  14.     "emailAddress" => "info@example.com"
  15.   )
  16. );
  17.  
  18.  
  19. $jsonData = json_encode($data);
  20.  
  21. echo "We're going to send this data\n";
  22. print_r ($jsonData);
  23. //  exit();
  24. // perform the curl transaction
  25. $ch = curl_init();
  26. curl_setopt ($ch, CURLOPT_URL, $url);
  27. curl_setopt ($ch, CURLOPT_USERPWD, $username . ":" . $password);
  28. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
  29. curl_setopt ($ch, CURLOPT_POST, true);
  30. curl_setopt ($ch, CURLOPT_POSTFIELDS, $jsonData);
  31. // curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
  32. curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
  33.  
  34. $response = curl_exec($ch);
  35. $decode = json_decode($response);
  36. print_r($decode);
  37.  
  38. ?>
  39. ///////////////////////////////////////////////////////
  40. ///////////////// run it //////////////////////////////
  41. php -f example.php
  42. ///////////////// results / output ////////////////////
  43. We're going to send this data
  44. [{"username":"example1","password":"mysecret","fullName":"Example Uno","emailAddress":"info@example.com"}]
  45.  
  46. stdClass Object
  47. (
  48.     [errorMessage] => Bad request (check parameters)
  49.     [errorDetail] => The email address entered is in an invalid format
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement