+ attachments() + + +
+ + +FreshBooks attachment upload resource with call to upload, get
+ +
+ public
+ attachments() : UploadResource
+
+ diff --git a/docs/html/classes/amcintosh-FreshBooks-Builder-BuilderInterface.html b/docs/html/classes/amcintosh-FreshBooks-Builder-BuilderInterface.html index 854e250..38876e1 100644 --- a/docs/html/classes/amcintosh-FreshBooks-Builder-BuilderInterface.html +++ b/docs/html/classes/amcintosh-FreshBooks-Builder-BuilderInterface.html @@ -98,6 +98,10 @@
FreshBooks attachment upload resource with call to upload, get
+ +
+ public
+ attachments() : UploadResource
+
+ FreshBooks image upload resource with call to upload, get
+ +
+ public
+ images() : UploadResource
+
+ A file that has been uploaded to FreshBooks.
+ + + + + + +
+ public
+ string
+ $fileName
+
+
+
+ The name of the file uploaded to FreshBooks.
+This is returned from the API in the X-filename
header.
+ public
+ string
+ $jwt
+
+
+
+ The JWT used to fetch the file from FreshBooks.
+
+ public
+ string
+ $link
+
+
+
+ A fully qualified path the the file from FreshBooks.
+
+ public
+ string
+ $mediaType
+
+
+
+ The media type (eg. image/png
) of the file uploaded to FreshBooks.
+ public
+ string
+ $responseBody
+
+
+
+ The PSR StreamInterface steam of data from the request body.
+
+ public
+ __construct(string|null $fileName, string|null $mediaType, StreamInterface|null $responseBody) : mixed
+
+ Attached files and images to include with an invoice.
+ +Note: This data is not in the default response and will only be +present with the use of a corresponding "includes" filter.
+
+ public
+ mixed
+ RESPONSE_FIELD
+ = 'expense'
+
+
+
+
+
+
+
+
+ public
+ int
+ $attachmentId
+
+
+
+ Duplicate of id
+
+ public
+ int
+ $expenseId
+
+
+
+ Id of the expense this attachment is associated with, if applicable.
+
+ public
+ int
+ $id
+
+
+
+ The unique identifier of this expense attachment within this business.
+
+ public
+ string
+ $jwt
+
+
+
+ JWT link to the attachment.
+
+ public
+ string
+ $mediaType
+
+
+
+ Type of the attachment.
+Get the data as an array to POST or PUT to FreshBooks, removing any read-only fields.
+ +
+ public
+ getContent() : array<string|int, mixed>
+
+
+ protected
+ mixed
+ DELETE
+ = 'DELETE'
+
+
+
+
+
+
+
+
+ protected
+ mixed
+ GET
+ = 'GET'
+
+
+
+
+
+
+
+
+ protected
+ mixed
+ PATCH
+ = 'PATCH'
+
+
+
+
+
+
+
+
+ protected
+ mixed
+ POST
+ = 'POST'
+
+
+
+
+
+
+
+
+ protected
+ mixed
+ PUT
+ = 'PUT'
+
+
+
+
+
+
+
+
+ protected
+ HttpClient
+ $httpClient
+
+
+
+
+
+
+
+ protected
+ string
+ $resourceName
+
+
+
+
+
+
+
+ protected
+ string
+ $uploadPath
+
+
+
+
+
+
+
+ public
+ __construct(HttpClient $httpClient, string $uploadPath, string $resourceName) : mixed
+
+ Get an uploaded file.
+ +
+ public
+ get(string $jwt) : FileUpload
+
+ JWT provided by FreshBooks when the file was uploaded.
+Object containing the file name, content type, and stream of data.
+Upload a file to FreshBooks.
+ +
+ public
+ upload(string $accountId, mixed $file) : FileUpload
+
+ The alpha-numeric account id
+Object containing the JWT, file name, content type.
+
+ protected
+ buildQueryString(array<string|int, mixed>|null $builders) : string
+
+ The the url to the upload resource.
+ +
+ protected
+ getUrl([string $accountId = null ][, string $jwt = null ]) : string
+
+ Create a FreshBooksException from the json response from the uploads endpoint.
+ +
+ protected
+ handleError(int $statusCode, string $contents) : void
+
+ HTTP status code
+The response contents
+Make a request against the uploads resource. Returns an object containing a +Psr\Http\Message\StreamInterface for flexibility.
+ +
+ private
+ makeGetFileRequest(string $url) : FileUpload
+
+ Throws a FreshBooksException if the response is not a 200.
+Make creates a POST request to upload a file to FreshBooks.
+ +
+ private
+ makeUploadRequest(string $url, mixed $file) : FileUpload
+
+ Throws a FreshBooksException if the response is not a 200.
+Not all resources have full CRUD methods available. For example expense categories have list
and get
calls, but are not deletable. If you attempt to call a method that does not exist, the SDK will raise a
diff --git a/docs/html/guide/api-calls/get-list.html b/docs/html/guide/api-calls/get-list.html
index dafe967..84cb7f3 100644
--- a/docs/html/guide/api-calls/get-list.html
+++ b/docs/html/guide/api-calls/get-list.html
@@ -99,6 +99,10 @@
Some FreshBooks resource can include images and attachments. For example, invoices can have a company +logo or banner image as part of the invoice presentation object as well as images or pdfs attachments. +Expenses can also include copies or photos of receipts as attachments.
+All images and attachments first need to be uploaded to FreshBooks via the images
or attachments
+endpoints.
These will then return a path to your file with a JWT. This path will can then be passed as part of the +data in a subsequent call.
+See FreshBooks' invoice attachment +and expense attachment +documentation for more information.
+See FreshBooks' API Documentation.
+The upload()
function takes a PHP resource.
+Logo's and banners are added to the invoice presentation object. To include an uploaded attachment on
+an invoice, the invoice request must include an attachments object.
$logo = $freshBooksClient->images()->upload($accountId, fopen('./sample_logo.png', 'r'));
+$attachment = $freshBooksClient->attachments()->upload($accountId, fopen('./sample_attachment.pdf', 'r'));
+
+$presentation = [
+ 'image_logo_src' => "/uploads/images/{$logo->jwt}",
+ 'theme_primary_color' => '#1fab13',
+ 'theme_layout' => 'simple'
+];
+
+$invoiceData = [
+ 'customerid' => $clientId,
+ 'attachments' => [
+ [
+ 'jwt' => $attachment->jwt,
+ 'media_type' => $attachment->mediaType
+ ]
+ ],
+ 'presentation' => presentation
+];
+
+$invoice = $freshBooksClient->invoices()->create($accountId, $invoiceData);
+ See FreshBooks' API Documentation.
+Expenses have have images or PDFs of the associated receipt attached. The expense request must include +an attachments object.
+$attachment = $freshBooksClient->attachments()->upload($accountId, fopen('./sample_receipt.pdf', 'r'));
+
+$expense->amount = new Money("6.49", "CAD");
+$expense->date = new DateTime();
+$expense->staffId = 1;
+$expense->categoryId = 3436009;
+
+$expenseAttachment = new ExpenseAttachment();
+$expenseAttachment->jwt = $attachment->jwt;
+$expenseAttachment->mediaType = $attachment->mediaType;
+
+$expense->attachment = $expenseAttachment;
+
+$includes = (new IncludesBuilder())->include('attachment');
+$expense = $freshBooksClient->expenses()->create($accountId, model: $expense, includes: $includes);
+