How to attach PDF File to Invoice

How to attach PDF File to Invoice

Hi 

I need Attach a PDF File to Invoice with the API zoho books. I created a script in PHP / Curl, but i can't attach a file. The script is this:


  1. $pdf = curl_file_create($File_with_full_path, "application/pdf");

  2. access_token();
  3. $url = "https://books.zoho.com/api/v3/invoices/".$id."/attachment?organization_id=".$OrgId;

  4. $curl = curl_init();
  5. curl_setopt_array($curl, array(
  6. CURLOPT_URL => $url,
  7. CURLOPT_RETURNTRANSFER => true,
  8. CURLOPT_ENCODING => "",
  9. CURLOPT_MAXREDIRS => 10,
  10. CURLOPT_TIMEOUT => 0,
  11. CURLOPT_FOLLOWLOCATION => false,
  12. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  13. CURLOPT_CUSTOMREQUEST => "POST",
  14. CURLOPT_POSTFIELDS => array('attachment'=> $pdf),
  15. CURLOPT_HTTPHEADER => array(
  16. "Authorization: Zoho-oauthtoken ".$_SESSION["AccTok"],
  17. "Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
  18. ),
  19. ));
  20. $response = curl_exec($curl);
  21. curl_close($curl);

I don't know what I'm doing wrong, but according to the API documentation my script would be correct, yet I only get error messages.

I would appreciate it if you could mention to me what mistake I am making