title: Fedena API curl call with POST XML file returns 400 error
body: <p>I'm trying to post the student data to fedena API. So If the API call is successfull, then it will add a student. But When i try this code, it is returning 400 error.</p>
  <p>MY CODE :</p>
  <pre><code>&lt;?php 
  
  session_start();
  function garland_curlapi_call($url,$headers = NULL,$method = NULL,$data = NULL){
       
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,$url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   
      if($headers != &quot;&quot;)
      {
          //curl_setopt($ch, CURLOPT_HTTPHEADER,true);
          curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
      }
      if($data != &quot;&quot;){ $data = http_build_query($data); }
      if($method == &quot;POST&quot;)
      {
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POST, count($data));
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      }
      $result = curl_exec($ch); // echo $result;
  
      $curl_info = curl_getinfo($ch);
      
      //print_r($curl_info); exit; 
      $content_type = explode(&quot;;&quot;,$curl_info['content_type']);
  
  
      if($content_type[0] == &quot;application/json&quot;){
          $result_data = json_decode($result,TRUE);
  
      }
      elseif($content_type[0] == &quot;application/xml&quot;){
          $xml = simplexml_load_string($result);
          $json = json_encode($xml);
          $result_data = json_decode($json,TRUE);
  
      }
      else {
          $result_data = $result;
      }
      if (curl_errno($ch))
      {
          return array(&quot;status&quot; =&gt; &quot;error&quot; , &quot;data&quot; =&gt; curl_error($ch) ,'curn_info' =&gt; $curl_info);
      }
      else
      {
          curl_close($ch);
          return array(&quot;status&quot; =&gt; &quot;success&quot; , &quot;data&quot; =&gt; $result_data ,'curn_info' =&gt; $curl_info);
      }
  }
  
  
  function garland_get_fedena_accesstoken($new = NULL)
  {
      if($_SESSION['fedena_access_key'] != &quot;&quot; &amp;&amp; $new == &quot;&quot;)
      {   
           return $_SESSION['fedena_access_key'];
           
      }
       
  }
  
  
  
  
  $xml = &quot;http://mywebsite.com/test/student.xml&quot;;
   
  $access_token = garland_get_fedena_accesstoken();
  $url = &quot;http://test.sandbox.fedena.com/api/students&quot;;
  $headers = array('Authorization: Token token=&quot;'.$access_token.'&quot;');
  $method = &quot;POST&quot;;
  $data = array(&quot;student&quot; =&gt; $xml);
  $result = garland_curlapi_call($url, $headers, $method, $data);
   
  
  print_r($result); 
  ?&gt;
  </code></pre>
  <p>OUTPUT :</p>
  <pre><code>Array
  (
      [status] =&gt; success
      [data] =&gt; Array
          (
              [error] =&gt; Array
                  (
                      [invalid_request_error] =&gt; Invalid request.
                  )
  
          )
  
      [curn_info] =&gt; Array
          (
              [url] =&gt; http://test.sandbox.fedena.com/api/students
              [content_type] =&gt; application/xml; charset=utf-8
              [http_code] =&gt; 400
              [header_size] =&gt; 606
              [request_size] =&gt; 305
              [filetime] =&gt; -1
              [ssl_verify_result] =&gt; 0
              [redirect_count] =&gt; 0
              [total_time] =&gt; 0.540113
              [namelookup_time] =&gt; 0.012328
              [connect_time] =&gt; 0.265829
              [pretransfer_time] =&gt; 0.265907
              [size_upload] =&gt; 64
              [size_download] =&gt; 135
              [speed_download] =&gt; 249
              [speed_upload] =&gt; 118
              [download_content_length] =&gt; 135
              [upload_content_length] =&gt; 64
              [starttransfer_time] =&gt; 0.540075
              [redirect_time] =&gt; 0
              [redirect_url] =&gt; 
              [primary_ip] =&gt; 54.254.105.83
              [certinfo] =&gt; Array
                  (
                  )
  
              [primary_port] =&gt; 80
              [local_ip] =&gt; 10.0.0.8
              [local_port] =&gt; 47643
          )
  
  )
  </code></pre>
  <p><strong>FEDENA DOCUMENTATION FOR THIS API CALL for creating a student :</strong></p>
  <p><strong>POST /api/students/</strong> </p>
  <p>It is for creating a student object in database. </p>
  <p><strong>Parameter needed:</strong>   </p>
  <pre><code>{'student':'STUDENT DETAIL XML FILE',’student_photo’:’&lt;PHOTO FILE&gt;’}    
  </code></pre>
  <p>N.B:Correct format of XML can be downloaded from /api/students/student_structure.The  required parameters are highlighted.parameter student is necessary.Others can be  skipped.       </p>
  <p><strong>Result:</strong> </p>
  <p>If successfully created ,the response will be like the following   </p>
  <pre><code>    &lt;student_detail&gt; 
   &lt;student&gt; 
   &lt;student_name&gt;DEBANJAN SEN GUPTA&lt;/student_name&gt; 
   &lt;batch_name&gt;A ­ TEST&lt;/batch_name&gt;  
  &lt;admission_date&gt;2013­04­05&lt;/admission_date&gt; 
   &lt;blood_group&gt;A+&lt;/blood_group&gt; 
   &lt;gender&gt;m&lt;/gender&gt;  
  &lt;nationality&gt;India&lt;/nationality&gt;
    &lt;language&gt;Bengali&lt;/language&gt;
    &lt;category/&gt;  &lt;religion&gt;Hinduism&lt;/religion&gt;  
  &lt;address&gt;HATIBAGAN BEADON STREET&lt;/address&gt;  
  &lt;city&gt;KOLKATA&lt;/city&gt;  
  &lt;state&gt;WEST BENGAL&lt;/state&gt;
    &lt;country&gt;India&lt;/country&gt; 
   &lt;phone&gt;03325436969&lt;/phone&gt;  
  &lt;mobile&gt;9620296538&lt;/mobile&gt;  
  &lt;email&gt;dave4u901@gmail.com&lt;/email&gt; 
   &lt;photo/&gt; 
   &lt;immediate_contact/&gt; 
   &lt;student_additional_details&gt;  &lt;additional_field&gt;  &lt;name&gt;Field 2&lt;/name&gt;  &lt;value&gt;TEST 2&lt;/value&gt;  &lt;/additional_field&gt;  &lt;additional_field&gt;  &lt;name&gt;Field 1&lt;/name&gt;  &lt;value&gt;TEST 1&lt;/value&gt;  &lt;/additional_field&gt;  &lt;/student_additional_details&gt;  &lt;/student&gt;  
  &lt;/student_detail&gt;  
  </code></pre>
  <p>  else if error occurs it will render the error like this   </p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF­8&quot;?&gt;  
      &lt;errors&gt;    
      &lt;error&gt;Admission date can't be blank&lt;/error&gt;  
         &lt;error&gt;First name can't be blank&lt;/error&gt; 
         &lt;error&gt;Batch can't be blank&lt;/error&gt;
          &lt;error&gt;Date of birth can't be blank&lt;/error&gt;  
      &lt;error&gt;Gender can't be blank&lt;/error&gt;
  &lt;/errors&gt;
  </code></pre>