title: PayPal API createInvoice returning always errorId 580001
body: <p>Code to invoke PayPal CreateInvoice API. It is always failing says "Invalid Request" and getting errorId 580001. I gone through the code that fills the request and API documention couple of times. No clue what data in Request is wrong.  What could be the wrong in the Request ? Am I missing something here?</p>
  
  <pre><code>function getInvoiceAPIHeader()
       {
           global $API_Username, $API_Password, $Signature;
  
           $API_Username = $this-&gt;config['username'];
           $API_Password = $this-&gt;config['password'];
           $Signature = $this-&gt;config['signature'];
  
  
           $headers[0] = "Content-Type: text/namevalue";               // either text/namevalue or text/xml
           $headers[1] = "X-PAYPAL-SECURITY-USERID: $API_Username";    //API user
           $headers[2] = "X-PAYPAL-SECURITY-PASSWORD: $API_Password";  //API PWD
           $headers[3] = "X-PAYPAL-SECURITY-SIGNATURE: $Signature";    //API Sig
           $headers[4] = "X-PAYPAL-APPLICATION-ID: {$this-&gt;APPLICATION_ID}";   //APP ID        
           $headers[6] = "X-PAYPAL-REQUEST-DATA-FORMAT: ".self::REQUEST_DATA_FORMAT."";   //Set Name Value Request Format
           $headers[7] = "X-PAYPAL-RESPONSE-DATA-FORMAT: ".self::RESPONSE_DATA_FORMAT.""; //Set Name Value Response Format     
  
           Debugger::dump($headers);
           return $headers;
       }
  
  
  
  function curlRequest($str_req)
   {      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $this-&gt;end_url);
      curl_setopt($ch, CURLOPT_VERBOSE, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 30);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $this-&gt;getInvoiceAPIHeader());     
  
      curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response, use for testing   
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POST, TRUE);
  
      // setting the NVP $my_api_str as POST FIELD to curl
      $log_req = $aryRresponse = explode("&amp;", $str_req);
      var_dump($log_req);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $str_req);
  
      // getting response from server
      $httpResponse = curl_exec($ch);
      //var_dump($httpResponse);
  
      if(!$httpResponse)
      {
          Debugger::dump("no response");
          $response = "{$this-&gt;end_url} failed: ".curl_error($ch)."(".curl_errno($ch).")";
          return $response;
      }
  
      $aryRresponse = explode("&amp;", $httpResponse);
      var_dump($aryRresponse);
      return $httpResponse;
   }
  </code></pre>
  
  <p>Request dump: </p>
  
  <pre><code>array(
      (int) 0 =&gt; 'Content-Type: text/namevalue',
      (int) 1 =&gt; 'X-PAYPAL-SECURITY-USERID: stest_1339339519_biz_api1.paypal.com',
      (int) 2 =&gt; 'X-PAYPAL-SECURITY-PASSWORD: 1339339539',
      (int) 3 =&gt; 'X-PAYPAL-SECURITY-SIGNATURE: A2I9zTt-d7IIbjVBlzNeLjVm9UJxAPoaKvgzcIz6c6G1-sLSKn5jcI3b',
      (int) 4 =&gt; 'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T',
      (int) 6 =&gt; 'X-PAYPAL-REQUEST-DATA-FORMAT: NV',
      (int) 7 =&gt; 'X-PAYPAL-RESPONSE-DATA-FORMAT: NV'
  )
  
  array
    0 =&gt; string 'invoice.merchantEmail=stest_1339339519_biz%40paypal.com' (length=55)
    1 =&gt; string 'invoice.payerEmail=stest_1340973819_per%40paypal.com' (length=52)
    2 =&gt; string 'invoice.currencyCode=USD' (length=24)
    3 =&gt; string 'invoice.number=PP-99' (length=20)
    4 =&gt; string 'invoice.paymentTerms=Net10' (length=26)
    5 =&gt; string 'invoice.itemList.item%281%29.name=Coke' (length=38)
    6 =&gt; string 'invoice.itemList.item%281%29.description=From+CocaCola' (length=54)
    7 =&gt; string 'invoice.itemList.item%281%29.quantity=2' (length=39)
    8 =&gt; string 'invoice.itemList.item%281%29.unitPrice=01.65' (length=44)
    9 =&gt; string 'invoice.itemList.item%281%29.taxName=Tax1' (length=41)
    10 =&gt; string 'invoice.itemList.item%281%29.taxRate=7' (length=38)
  </code></pre>
  
  <p>Response dump:</p>
  
  <pre><code> array
        0 =&gt; string 'HTTP/1.1 200 OK
      Date: Mon, 02 Jul 2012 17:06:05 GMT
      Server: Apache-Coyote/1.1
      CACHE-CONTROL: no-cache
      X-PAYPAL-MESSAGE-PROTOCOL: NONE
      X-PAYPAL-RESPONSE-DATA-FORMAT: NV
      X-EBAY-SOA-REQUEST-ID: 13848a7f-b860-a486-d656-c516ffffc6d8!Invoice!10.72.109.101![]
      X-PAYPAL-OPERATION-NAME: CreateInvoice
      X-PAYPAL-SERVICE-NAME: {http://svcs.paypal.com/types/pt}Invoice
      X-PAYPAL-SERVICE-VERSION: 1.0.0
      X-PAYPAL-ERROR-RESPONSE: TRUE
      Content-Type: text/plain;charset=UTF-8
      Set-Cookie: Apache=10.72.109.11.13412487648'... (length=679)
        1 =&gt; string 'responseEnvelope.ack=Failure' (length=28)
        2 =&gt; string 'responseEnvelope.correlationId=4cab848d7c2a0' (length=44)
        3 =&gt; string 'responseEnvelope.build=2910623' (length=30)
        4 =&gt; string 'error(0).errorId=580001' (length=23)
        5 =&gt; string 'error(0).domain=PLATFORM' (length=24)
        6 =&gt; string 'error(0).subdomain=Application' (length=30)
        7 =&gt; string 'error(0).severity=Error' (length=23)
        8 =&gt; string 'error(0).category=Application' (length=29)
        9 =&gt; string 'error(0).message=Invalid+request%3A+%7B0%7D' (length=43)
  </code></pre>
  
  <p>What could be the wrong in the Request ? Any Pointers ?</p>