cbfreshbooks

Class SDK

lucee.Component
    extended by cbfreshbooks.SDK

This is the Freshbooks SDK class

Class Attributes:
  • threadsafe
  •  
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
    Property Summary
    type property default serializable required
    any authorizationCode
          Authorization code.

    • access = public
    • returntype = any
    true false
    any cache


    • access = public
    • returntype = any
    true false
    any cachebox


    • access = public
    • returntype = any
    • inject = cachebox
    true false
    any identityInformation
          Store the identity of the current user.

    • access = public
    • returntype = any
    true false
    any log


    • access = public
    • returntype = any
    • inject = logbox:logger:{this}
    true false
    any refreshToken


    • access = public
    • returntype = any
    true false
    any settings
          The module settings.

    • access = public
    • returntype = any
    true false
    any tokenAccess
          Access token and refresh token.

    • access = public
    • returntype = any
    true false
    Constructor Summary
    init(any settings, any cachebox)
          Constructor.
    Method Summary
    struct authenticate()
         Do the authentication process and retrieve the token access from a given authorization code (Use the activation handler to retrieve the auth code).
    struct authResponse(any response)
         Manage response and build an struct with the token information and store it in the cache.
    string buildAuthorizationURL()
         Generate the authorization link to retrieve the authorization code.
    struct createEstimate(string accountID, struct estimateInfo)
         Create an estimate.
    struct createExpense(string accountID, struct expenseInfo)
         Create an expense.
    struct createInvoice(string accountID, struct invoiceInfo)
         Create an invoice.
    struct createItem(string accountID, struct itemInfo)
         Create item.
    struct createPayment(string accountID, struct paymentInfo)
         Create payment.
    struct createProject(string businessID, struct projectInfo)
         Create a new project.
    struct createSingleClient(string accountID, struct userInfo)
         Create a single client.
    struct createTax(string accountID, struct taxInfo)
         Create tax.
    struct createTimeEntry(string accountID, string businessID, struct timeEntryInfo)
         Create time entry.
    any deleteEstimate(string accountID, string estimateID, struct estimateFlag)
         Delete an estimate.
    any deleteExpense(string accountID, string expenseID, struct expenseFlag)
         Delete an expense.
    any deleteInvoice(string accountID, string invoiceID, struct invoiceFlag)
         Delete an invoice.
    any deleteItem(string accountID, string itemID, struct itemInfo)
         Delete item.
    any deletePayment(string accountID, string paymentID, struct paymentInfo)
         Delete payment.
    struct deleteProject(string businessID, string projectID, struct projectInfo)
         Delete a project.
    any deleteSingleClient(string accountID, string clientID, struct userFlag)
         Delete single client -> It passes an struct with a key "vis_state" = 1 to delete that client.
    any deleteStaff(string accountID, string staffID, struct staffInfo)
         delete a staff member.
    any deleteTax(string accountID, string taxID)
         delete tax.
    any deleteTimeEntry(string accountID, string businessID, string timeEntryID)
         Delete time entry.
    any getAuthenticationCredentials()
         Retrieve the authentication credentials for this modules.
    string getAuthorizationCode()
    string getCache()
    string getCachebox()
    array getClients(string accountID)
         Return the list of clients, if a 404 NOT FOUND error is thrown by the request, an empty array is returned.
    struct getEstimateById(string accountID, string estimateID)
         Returns a single estimate if it exists.
    array getEstimatesList(string accountID)
         Get the list of estimates.
    struct getExpenseById(string accountID, string expenseID)
         Returns a single expense, if it does not exist returns an empty struct.
    array getExpenseCategoriesList(string accountID)
         Get the list of expense categories.
    struct getExpenseCategoryById(string accountID, string expenseCategoryID)
         Returns a single expense category if it exists.
    array getExpensesList(string accountID)
         Retrieve the list of expenses.
    array getGatewaysList(string accountID)
         Get the list of gateways.
    string getIdentityInformation()
    struct getInvoiceById(string accountID, string invoiceID)
         Returns a single invoice if it exists.
    array getInvoicesList(string accountID)
         Get the list of invoices.
    struct getItemById(string accountID, string itemID)
         Returns a single item if it exists.
    array getItemsList(string accountID)
         Get the list of items.
    string getLog()
    struct getPaymentById(string accountID, string paymentID)
         Returns a single payment if it exists.
    array getPaymentsList(string accountID)
         Get the list of payments.
    struct getProjectById(string businessID, string projectID)
         Returns a single project if it exists.
    array getProjectsList(string businessID)
         Get the list of the projects associated with a business ID.
    string getRefreshToken()
    string getSettings()
    struct getSingleClient(string accountID, string clientID)
         Retrieve a single client.
    struct getStaffById(string accountID, string staffID)
         Returns a single staff member if it exists.
    array getStaffList(string accountID)
         Get the list of the staff.
    struct getTaskById(string accountID, string taskID)
         Returns a single task if it exists.
    struct getTaxById(string accountID, string taxID)
         Returns a single tax if it exists.
    array getTaxesList(string accountID)
         Get the list of taxes.
    array getTimeEntries(string businessID)
         Get time entries.
    string getTokenAccess()
    boolean isAuth()
         Check if the freshbooks account is authenticated (struct stored in cache).
    private struct makeRequest([string method='GET'], string url, [any body='[runtime expression]'], [struct headers='[runtime expression]'], [struct parameters='[runtime expression]'], [string type='R'], [numeric timeout='15'])
         Make a request to FreshBooks API.
    struct refreshToken(string refreshToken)
         I take the refresh token from the autehntication procedure and get you a new access token.
    any revokeAccess()
         Revoke Access to the freshbooks account.
    any setAuthorizationCode(any authorizationCode)
    any setCache(any cache)
    any setCachebox(any cachebox)
    any setIdentityInformation(any identityInformation)
    any setLog(any log)
    any setRefreshToken(any refreshToken)
    any setSettings(any settings)
    any setTokenAccess(any tokenAccess)
    any testCall()
         Make a test call.
    struct updateEstimate(string accountID, string estimateID, struct estimateInfo)
         Update an estimate.
    struct updateExpense(string accountID, string expenseID, struct expenseInfo)
         Update an expense.
    struct updateInvoice(string accountID, string invoiceID, struct invoiceInfo)
         Update an invoice.
    struct updateItem(string accountID, string itemID, struct itemInfo)
         Update an item.
    struct updatePayment(string accountID, string paymentID, struct paymentInfo)
         Update payment.
    struct updateProject(string businessID, string projectID, struct projectInfo)
         Update a project.
    struct updateSingleClient(string accountID, string clientID, struct userInfo)
         Update single client.
    struct updateStaff(string accountID, string staffID, struct staffInfo)
         update a staff member.
    struct updateTax(string accountID, string taxID, struct taxInfo)
         update tax.
    struct updateTimeEntry(string accountID, string businessID, string timeEntryID, struct timeEntryInfo)
         Update time entry.
     
    Methods inherited from class lucee.Component
    None

    Constructor Detail

    init

    public init(any settings, any cachebox)

    Constructor

    Parameters:
    settings - The module settings
    cachebox - The CacheBox reference

    Property Detail

    authorizationCode

    property any authorizationCode

    Authorization code

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    cache

    property any cache

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    cachebox

    property any cachebox

    Attributes:
    access - public
    required - false
    returntype - any
    inject - cachebox
    serializable - true

    identityInformation

    property any identityInformation

    Store the identity of the current user

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    log

    property any log

    Attributes:
    access - public
    required - false
    returntype - any
    inject - logbox:logger:{this}
    serializable - true

    refreshToken

    property any refreshToken

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    settings

    property any settings

    The module settings

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    tokenAccess

    property any tokenAccess

    Access token and refresh token

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    authenticate

    public struct authenticate()

    Do the authentication process and retrieve the token access from a given authorization code (Use the activation handler to retrieve the auth code) Authenticate the first time, after that returns the struct stored in cache, if the token has expired, it calls the refreshToken method and get a new token access


    authResponse

    public struct authResponse(any response)

    Manage response and build an struct with the token information and store it in the cache

    Parameters:
    response - HTTP Response

    buildAuthorizationURL

    public string buildAuthorizationURL()

    Generate the authorization link to retrieve the authorization code The user has to allow manually the access to the FreshBooks account and paste the authorization code into the module settings


    createEstimate

    public struct createEstimate(string accountID, struct estimateInfo)

    Create an estimate

    Parameters:
    accountID - The account ID associated with the estimate that will be created
    estimateInfo - The struct with the estimate's info to create a new entry

    createExpense

    public struct createExpense(string accountID, struct expenseInfo)

    Create an expense

    Parameters:
    accountID - The account ID where the expense will be created in
    expenseInfo - The struct with the expense's info to create a new entry

    createInvoice

    public struct createInvoice(string accountID, struct invoiceInfo)

    Create an invoice

    Parameters:
    accountID - The account ID associated with the invoice that will be created
    invoiceInfo - The struct with the invoice's info to create a new entry

    createItem

    public struct createItem(string accountID, struct itemInfo)

    Create item

    Parameters:
    accountID - The account ID associated with the item that will be created
    itemInfo - struct with the item's info to create a new entry

    createPayment

    public struct createPayment(string accountID, struct paymentInfo)

    Create payment

    Parameters:
    accountID - The account ID Associated with the payment to create
    paymentInfo - struct with the payment's info to create a new entry

    createProject

    public struct createProject(string businessID, struct projectInfo)

    Create a new project

    Parameters:
    businessID - The business ID associated with the project to create
    projectInfo - struct with the project's info to create a new entry

    createSingleClient

    public struct createSingleClient(string accountID, struct userInfo)

    Create a single client

    Parameters:
    accountID - The account ID where the client will be created in
    userInfo - The struct with the client's info to create a new entry

    createTax

    public struct createTax(string accountID, struct taxInfo)

    Create tax

    Parameters:
    accountID - The account ID Associated with the tax to create
    taxInfo - struct with the tax's info to create a new entry

    createTimeEntry

    public struct createTimeEntry(string accountID, string businessID, struct timeEntryInfo)

    Create time entry meta { pages, total_logged, total_unbilled, per_page, total, page } }

    Parameters:
    accountID - The account ID Associated with the time entry to create
    businessID - The business ID associated with the time entry to create
    timeEntryInfo - struct with the time entry's info to create a new entry

    deleteEstimate

    public any deleteEstimate(string accountID, string estimateID, struct estimateFlag)

    Delete an estimate

    Parameters:
    accountID - The account ID associated with the estimate that will be deleted
    estimateID - ID of the estimate that will be deleted
    estimateFlag - The struct with key 'vis_state' set to 1 to delete an existing estimate

    deleteExpense

    public any deleteExpense(string accountID, string expenseID, struct expenseFlag)

    Delete an expense

    Parameters:
    accountID - The account ID associated with the expense will be deleted
    expenseID - ID of the expense to delete
    expenseFlag - The struct with the key 'vis_state' set to 1 to delete an expense

    deleteInvoice

    public any deleteInvoice(string accountID, string invoiceID, struct invoiceFlag)

    Delete an invoice

    Parameters:
    accountID - The account ID associated with the invoice that will be deleted
    invoiceID - Id of the invoice to delete
    invoiceFlag - The struct with the invoice's info to update an existing entry

    deleteItem

    public any deleteItem(string accountID, string itemID, struct itemInfo)

    Delete item

    Parameters:
    accountID - The account ID of the items to list
    itemID - ID of the item to delete
    itemInfo - struct with the item's key 'vis_state' set to 1 to delete its entry

    deletePayment

    public any deletePayment(string accountID, string paymentID, struct paymentInfo)

    Delete payment

    Parameters:
    accountID - The account ID Associated with the payment to delete
    paymentID - ID of the payment to delete
    paymentInfo - struct with the key 'vis_state' set to 1 to delete its entry

    deleteProject

    public struct deleteProject(string businessID, string projectID, struct projectInfo)

    Delete a project

    Parameters:
    businessID - The business ID associated with the project to delete
    projectID - ID of the project to delete
    projectInfo - struct with the project's info to delete

    deleteSingleClient

    public any deleteSingleClient(string accountID, string clientID, struct userFlag)

    Delete single client -> It passes an struct with a key "vis_state" = 1 to delete that client

    Parameters:
    accountID - The account ID where the client belongs to
    clientID - Id of the client to delete
    userFlag - The struct with key 'vis_state' set to 1 to delete a single client

    deleteStaff

    public any deleteStaff(string accountID, string staffID, struct staffInfo)

    delete a staff member updated, p_province, p_city, p_code, p_country, accounting_systemid, bus_phone, signup_date, language, level, userid, p_street2, vis_state, fname, organization, p_street, currency_code}

    Parameters:
    accountID - The account ID Associated with the staff member to delete
    staffID - Id of the staff member to delete
    staffInfo - struct with the staff's info to delete

    deleteTax

    public any deleteTax(string accountID, string taxID)

    delete tax

    Parameters:
    accountID - The account ID Associated with the tax to delete
    taxID - Id of the tax to delete

    deleteTimeEntry

    public any deleteTimeEntry(string accountID, string businessID, string timeEntryID)

    Delete time entry

    Parameters:
    accountID - The account ID Associated with the time entry to create
    businessID - The business ID associated with the time entry to create
    timeEntryID - Id of the time entry to update

    getAuthenticationCredentials

    public any getAuthenticationCredentials()

    Retrieve the authentication credentials for this modules


    getAuthorizationCode

    public string getAuthorizationCode()


    getCache

    public string getCache()


    getCachebox

    public string getCachebox()


    getClients

    public array getClients(string accountID)

    Return the list of clients, if a 404 NOT FOUND error is thrown by the request, an empty array is returned

    Parameters:
    accountID - The account ID that the client belongs to
    Throws:
    an error if something goes wrong with the request

    getEstimateById

    public struct getEstimateById(string accountID, string estimateID)

    Returns a single estimate if it exists

    Parameters:
    accountID - Account Id where the estimate belongs to
    estimateID - Id of the estimate to return

    getEstimatesList

    public array getEstimatesList(string accountID)

    Get the list of estimates

    Parameters:
    accountID - The account ID of the estimates to list

    getExpenseById

    public struct getExpenseById(string accountID, string expenseID)

    Returns a single expense, if it does not exist returns an empty struct

    Parameters:
    accountID - Account Id where the expense belong to
    expenseID - Id of the expense to return

    getExpenseCategoriesList

    public array getExpenseCategoriesList(string accountID)

    Get the list of expense categories is_cogs:boolean, parentid, vis_state:number, id:number } , {category2}, ... ]

    Parameters:
    accountID - The account ID of the expense categories to list

    getExpenseCategoryById

    public struct getExpenseCategoryById(string accountID, string expenseCategoryID)

    Returns a single expense category if it exists is_cogs:boolean, parentid, vis_state:number, id:number }

    Parameters:
    accountID - Account Id where the expense category belongs to
    expenseCategoryID - Id of the expense category to return

    getExpensesList

    public array getExpensesList(string accountID)

    Retrieve the list of expenses expense -> { categoryid, markup_percent, projectid, clientid, isduplicate, taxName2, taxName1, taxPercent1, profileid, taxPercent2, id, invoiceid, account_name, taxAmount2, taxAmount1, vis_state, status, bank_name, updated, vendor, has_receipt, ext_systemid, staffid, date, transactionid, include_receipt, accounting_systemid, background_jobid, notes, ext_invoiceid, amount, expenseid, compounded_tax, accountid }

    Parameters:
    accountID - The account ID of the expenses to list

    getGatewaysList

    public array getGatewaysList(string accountID)

    Get the list of gateways

    Parameters:
    accountID - The account ID of the gateways to list

    getIdentityInformation

    public string getIdentityInformation()


    getInvoiceById

    public struct getInvoiceById(string accountID, string invoiceID)

    Returns a single invoice if it exists

    Parameters:
    accountID - Account Id where the invoice belong to
    invoiceID - Id of the invoice to return

    getInvoicesList

    public array getInvoicesList(string accountID)

    Get the list of invoices invoice -> { status, deposit_percentage, create_date, outstanding, payment_status, street, code, ownerid, vat_number, id, gmail, vat_name, v3_status, discount_description, dispute_status, lname, deposit_status, ext_archive, template, basecampid, sentid, show_attachments, vis_state, current_organization, province, due_date, updated, terms, description, parent, last_order_status, street2, deposit_amount, paid, invoiceid, discount_total, address, invoice_number, customerid, discount_value, accounting_systemid, organization, due_offset_days, language, po_number, display_status, created_at, auto_bill, date_paid, amount, estimateid, city, currency_code, country, autobill_status, generation_date, return_uri, fname, notes, payment_details, accountid }

    Parameters:
    accountID - The account ID of the invoices to list

    getItemById

    public struct getItemById(string accountID, string itemID)

    Returns a single item if it exists

    Parameters:
    accountID - Account Id where the item belongs to
    itemID - Id of the item to return

    getItemsList

    public array getItemsList(string accountID)

    Get the list of items

    Parameters:
    accountID - The account ID of the items to list

    getLog

    public string getLog()


    getPaymentById

    public struct getPaymentById(string accountID, string paymentID)

    Returns a single payment if it exists

    Parameters:
    accountID - Account Id where the payment belongs to
    paymentID

    getPaymentsList

    public array getPaymentsList(string accountID)

    Get the list of payments

    Parameters:
    accountID - The account ID of the payments to list

    getProjectById

    public struct getProjectById(string businessID, string projectID)

    Returns a single project if it exists

    Parameters:
    businessID - The business ID associated with the projects to list
    projectID - ID of the project to retrieve

    getProjectsList

    public array getProjectsList(string businessID)

    Get the list of the projects associated with a business ID

    Parameters:
    businessID - The business ID associated with the projects to list

    getRefreshToken

    public string getRefreshToken()


    getSettings

    public string getSettings()


    getSingleClient

    public struct getSingleClient(string accountID, string clientID)

    Retrieve a single client

    Parameters:
    accountID - The account ID that the client belongs to
    clientID - ID of the client to retrieve

    getStaffById

    public struct getStaffById(string accountID, string staffID)

    Returns a single staff member if it exists updated, p_province, p_city, p_code, p_country, accounting_systemid, bus_phone, signup_date, language, level, userid, p_street2, vis_state, fname, organization, p_street, currency_code}

    Parameters:
    accountID - Account Id where the staff member belongs to
    staffID - Id of the staff member to return

    getStaffList

    public array getStaffList(string accountID)

    Get the list of the staff username, updated, p_province, p_city, p_code, p_country, accounting_systemid, bus_phone, signup_date, language, level, userid, p_street2, vis_state, fname, organization, p_street, currency_code}, ... ]

    Parameters:
    accountID - The account ID of the staff to list

    getTaskById

    public struct getTaskById(string accountID, string taskID)

    Returns a single task if it exists

    Parameters:
    accountID - Account Id where the task belongs to
    taskID - ID of the task to retrieve

    getTaxById

    public struct getTaxById(string accountID, string taxID)

    Returns a single tax if it exists

    Parameters:
    accountID - Account Id where the tax belongs to
    taxID

    getTaxesList

    public array getTaxesList(string accountID)

    Get the list of taxes

    Parameters:
    accountID - The account ID of the taxes to list

    getTimeEntries

    public array getTimeEntries(string businessID)

    Get time entries meta { pages, total_logged, total_unbilled, per_page, total, page } }

    Parameters:
    businessID - The business ID associated with the time entries

    getTokenAccess

    public string getTokenAccess()


    isAuth

    public boolean isAuth()

    Check if the freshbooks account is authenticated (struct stored in cache)


    makeRequest

    private struct makeRequest([string method='GET'], string url, [any body='[runtime expression]'], [struct headers='[runtime expression]'], [struct parameters='[runtime expression]'], [string type='R'], [numeric timeout='15'])

    Make a request to FreshBooks API

    Parameters:
    method - The HTTP method call
    url - The url to make the request
    body - The body contents of the request
    headers - Request headers
    parameters - Request parameters
    type - Flag to determine the type of request, "A" for authenticaton request and "R" for other requests
    timeout - Request Timeout

    refreshToken

    public struct refreshToken(string refreshToken)

    I take the refresh token from the autehntication procedure and get you a new access token.

    Parameters:
    refreshToken - the most recent refresh token that has been provided

    revokeAccess

    public any revokeAccess()

    Revoke Access to the freshbooks account Remove token access, refresh token, authorization code and authorization struct from the application


    setAuthorizationCode

    public any setAuthorizationCode(any authorizationCode)

    Parameters:
    authorizationCode

    setCache

    public any setCache(any cache)

    Parameters:
    cache

    setCachebox

    public any setCachebox(any cachebox)

    Parameters:
    cachebox

    setIdentityInformation

    public any setIdentityInformation(any identityInformation)

    Parameters:
    identityInformation

    setLog

    public any setLog(any log)

    Parameters:
    log

    setRefreshToken

    public any setRefreshToken(any refreshToken)

    Parameters:
    refreshToken

    setSettings

    public any setSettings(any settings)

    Parameters:
    settings

    setTokenAccess

    public any setTokenAccess(any tokenAccess)

    Parameters:
    tokenAccess

    testCall

    public any testCall()

    Make a test call It will be deleted later


    updateEstimate

    public struct updateEstimate(string accountID, string estimateID, struct estimateInfo)

    Update an estimate

    Parameters:
    accountID - The account ID associated with the estimate that will be updated
    estimateID - ID of the estimate that will be updated
    estimateInfo - The struct with the estimate's info to update

    updateExpense

    public struct updateExpense(string accountID, string expenseID, struct expenseInfo)

    Update an expense

    Parameters:
    accountID - The account ID associated with the expense that will be updated
    expenseID - ID of the expense to update
    expenseInfo - The struct with the expense's info to create a new entry

    updateInvoice

    public struct updateInvoice(string accountID, string invoiceID, struct invoiceInfo)

    Update an invoice

    Parameters:
    accountID - The account ID associated with the invoice that will be updated
    invoiceID - Id of the invoice to update
    invoiceInfo - The struct with the invoice's info to create a new entry

    updateItem

    public struct updateItem(string accountID, string itemID, struct itemInfo)

    Update an item

    Parameters:
    accountID - The account ID associated with the item to update
    itemID - ID of the item to update
    itemInfo - struct with the item's info to update

    updatePayment

    public struct updatePayment(string accountID, string paymentID, struct paymentInfo)

    Update payment

    Parameters:
    accountID - The account ID Associated with the payment to update
    paymentID - ID of the payment to update
    paymentInfo - struct with the payment's info to update

    updateProject

    public struct updateProject(string businessID, string projectID, struct projectInfo)

    Update a project

    Parameters:
    businessID - The business ID associated with the project to update
    projectID - ID of the project to update
    projectInfo - struct with the project's info to update

    updateSingleClient

    public struct updateSingleClient(string accountID, string clientID, struct userInfo)

    Update single client

    Parameters:
    accountID - The account ID where the client belongs to
    clientID - Id of the client to update
    userInfo - The struct with the client's data to update

    updateStaff

    public struct updateStaff(string accountID, string staffID, struct staffInfo)

    update a staff member updated, p_province, p_city, p_code, p_country, accounting_systemid, bus_phone, signup_date, language, level, userid, p_street2, vis_state, fname, organization, p_street, currency_code}

    Parameters:
    accountID - The account ID Associated with the staff member to update
    staffID - Id of the staff member to update
    staffInfo - struct with the staff's info to update a new entry

    updateTax

    public struct updateTax(string accountID, string taxID, struct taxInfo)

    update tax

    Parameters:
    accountID - The account ID Associated with the tax to update
    taxID - Id of the tax to update
    taxInfo - struct with the tax's info to update a new entry

    updateTimeEntry

    public struct updateTimeEntry(string accountID, string businessID, string timeEntryID, struct timeEntryInfo)

    Update time entry meta { pages, total_logged, total_unbilled, per_page, total, page } }

    Parameters:
    accountID - The account ID Associated with the time entry to update
    businessID - The business ID associated with the time entry to update
    timeEntryID - Id of the time entry to update
    timeEntryInfo - struct with the time entry's info to update