Weble / ZohoBooksApi

40 stars 39 forks source link

How to Attach and View Files for an Invoice? #115

Open shajeerEmiratesZone opened 4 months ago

shajeerEmiratesZone commented 4 months ago

Hi, I'm trying to attach Files to Invoice and retrieve them using Zohobooks API. But I don't see any option for this. Can anyone guide me how to do this using the package or if the implementation exist in the package. The URL for file attachment (POST) and retrieval (GET) is : https://zohoapis.com/books/v3/invoices/{invoiceID}/attachment?organization_id={org_id};

Skullbock commented 4 months ago

Hi, i don't think there is a dedicated method yet in the API. Check the doAction method on the module $zoho->invoices->doAction($id, 'attachment', $data) if can cover the use case.

Otherwise, PR are welcome!

shajeerEmiratesZone commented 4 months ago

Hello,

Thank you for your reply. How can I send the attachment file here? Using cURL, I can upload the attachment as shown in the code below:

$tmpfile = $file['tmp_name'];
$filename = basename($file['name']);
$cFile = curl_file_create($tmpfile, $file['type'], $filename);
$post = [
    'can_send_in_mail' => 'false',
    'attachment' => $cFile
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Zoho-oauthtoken ' . $accessToken,
]);

$response = curl_exec($ch);
curl_close($ch);

$response_data = json_decode($response);
return $response_data;
Skullbock commented 4 months ago

Hi! if you can PR the feature, the best place to do so is to add a new method, like uploadAttachment to the invoices module. You can find a similar method here:

https://github.com/Weble/ZohoBooksApi/blob/develop/src/Modules/Invoices.php#L140