Jump to content

Attach documents to clients via API ?


wonderdev

Recommended Posts

22 hours ago, wonderdev said:

We have client contracts that is generated in our external system, is there a API function etc. to easy attach files to clients or do we have to do this manually per clients? !

i'm not aware of any API for client downloads (technically uploads I suppose) - there are some for attaching files to tickets, but not this.... also, i'm not aware of any third-party addon that can do this either.

I suppose it is possible to write a solution that uploads the file to the downloads directory and updates the appropriate database table with filename/client details - but not via the default API.

Link to comment
Share on other sites

Workaround 1: Instead of sending an email, attach your file via API in a ticket with OpenTicket or AddTicketReply.

Workaround 2: Alternatively provide a download link in your email. They can download the contract on click.

If you really want to attach the file then why don't you simply use PHPMailer included in WHMCS? In pseudo-code it would be something like this.

<?php

// Require the autoloader
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';

// Get the necessary data from tblconfiguration
$conf = GetWHMCSConfig(array('CompanyName', 'Email', 'MailType', 'SMTPHost', 'SMTPUsername', 'SMTPPassword', 'SMTPort'));

// $conf->CompanyName would be your Company Name set in WHMCS. Same goes for Email, MailType etc. Don't forget to Decrypt($conf->SMTPPassword)

$mail = new PHPMailer;
$mail->Port       = $conf->SMTPort;
$mail->Username   = $conf->SMTPUsername;
$mail->Password   = Decrypt($conf->SMTPPassword);

// ... and all the usual stuff...

$mail->Subject = 'Accept this contract';
$mail->MsgHTML('Please sign your name in blood');

// ... attach your file and...

$mail->Send();

// Done

 

Link to comment
Share on other sites

This has to be done via the database;

$ClientFile = Capsule::table('tblclientsfiles')
    ->insert( array('userid'=>1,
        "title"=> "The great file",
        'filename'=>"greatfile.doc",
        'dateadded'=>date('Y-m-d')) );

Filename should be a file within the attachments directory.   I also have heard that the filename needs to be prefixed with "file6DigitNumber" where "6DigitNumber" is a random number but I don't think that is 100% required.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated