Class FreshBooksClient

java.lang.Object
net.amcintosh.freshbooks.FreshBooksClient

public class FreshBooksClient extends Object
FreshBooks API client.

 FreshBooksClient freshBooksClient = new FreshBooksClient.FreshBooksClientBuilder("your application id")
     .withToken("a valid token")
     .build();
 
  • Method Details

    • getVersion

      public String getVersion()
      Get the freshbooks-sdk version.
      Returns:
      the version number
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAuthRequestUri

      public String getAuthRequestUri()
      Returns the url that a client needs to request an oauth grant from the server.

      To get an oauth access token, send your user to this URL. The user will be prompted to log in to FreshBooks, after which they will be redirected to the `redirectUri` set on the client with the access grant as a parameter. That grant can then be used to fetch an access token by calling `getAccessToken`.

      If scopes are not specified, then the access token will be given the default scopes your application is registered for.

      Note: The `redirectUri` must be one of the URLs your application is registered for.
      Returns:
      The URL for the authorization request
      See Also:
    • getAuthRequestUri

      public String getAuthRequestUri(List<String> scopes)
      Returns the url that a client needs to request an oauth grant from the server.

      To get an oauth access token, send your user to this URL. The user will be prompted to log in to FreshBooks, after which they will be redirected to the `redirectUri` set on the client with the access grant as a parameter. That grant can then be used to fetch an access token by calling `getAccessToken`.

      If scopes are not specified, then the access token will be given the default scopes your application is registered for.

      Note: The `redirectUri` must be one of the URLs your application is registered for.
      Parameters:
      scopes - List of scopes if your want an access token with only a subset of your registered scopes.
      Returns:
      The URL for the authorization request
      See Also:
    • getAccessToken

      public AuthorizationToken getAccessToken(String code) throws FreshBooksException
      Makes a call to the FreshBooks token URL to get an access_token.

      This requires the access_grant code obtained after the user is redirected by the authorization step. See getAuthRequestUri().

      This call sets the authorization token details on the FreshBooksClient instance and then returns those values in an AuthorizationToken.
      Parameters:
      code - access_grant code from the authorization redirect
      Returns:
      Throws:
      FreshBooksException
    • refreshAccessToken

      public AuthorizationToken refreshAccessToken() throws FreshBooksException
      Makes a call to the FreshBooks token URL to refresh an access_token.

      This requires the AuthorizationToken on the client to have a valid refreshToken

      This call sets the authorization token details on the FreshBooksClient instance and then returns those values in an AuthorizationToken.
      Returns:
      Throws:
      FreshBooksException
    • request

      public com.google.api.client.http.HttpRequest request(String requestMethod, String resourceUrl) throws IOException
      Make a request to FreshBooks.
      Parameters:
      requestMethod - GET, POST, PUT, DELETE
      resourceUrl - Relative URL (eg. /accounting/account/{accountId}/users/clients)
      Returns:
      HttpRequest object
      Throws:
      IOException
    • request

      public com.google.api.client.http.HttpRequest request(String requestMethod, String resourceUrl, @Nullable Map<String,Object> data) throws IOException
      Make a request to FreshBooks with a data payload.
      Parameters:
      requestMethod - GET, POST, PUT, DELETE
      resourceUrl - Relative URL (eg. /accounting/account/{accountId}/users/clients)
      data -
      Returns:
      HttpRequest object
      Throws:
      IOException
    • currentUser

      public Identity currentUser() throws FreshBooksException
      The identity details of the currently authenticated user.
      Throws:
      FreshBooksException
      See Also:
    • clients

      public Clients clients()
      FreshBooks clients resource with calls to get, list, create, update, delete.
      Returns:
      Clients resource initialized with this FreshBooksClient
    • expenses

      public Expenses expenses()
      FreshBooks expenses resource with calls to get, list, create, update, delete.
      Returns:
      Expenses resource initialized with this FreshBooksClient
    • invoices

      public Invoices invoices()
      FreshBooks invoices resource with calls to get, list, create, update, delete.
      Returns:
      Invoices resource initialized with this FreshBooksClient
    • items

      public Items items()
      FreshBooks items resource with calls to get, list, create, update, delete.
      Returns:
      Items resource initialized with this FreshBooksClient
    • otherIncomes

      public OtherIncomes otherIncomes()
      FreshBooks other income resource with calls to get, list, create, update, delete.
      Returns:
      OtherIncomes resource initialized with this FreshBooksClient
    • payments

      public Payments payments()
      FreshBooks payments resource with calls to get, list, create, update, delete.
      Returns:
      Payments resource initialized with this FreshBooksClient
    • projects

      public Projects projects()
      FreshBooks projects resource with calls to get, list, create, update, delete.
      Returns:
      Projects resource initialized with this FreshBooksClient
    • reports

      public AccountingReports reports()
      FreshBooks reports resource with calls the various reports available.

      Eg. freshbooksClient.reports.profitAndLoss(accountId)
      Returns:
      Reports resource initialized with this FreshBooksClient
    • services

      public Services services()
      FreshBooks services resource with calls to get, list, create, update, delete.
      Returns:
      Services resource initialized with this FreshBooksClient
    • serviceRates

      public ServiceRates serviceRates()
      FreshBooks service rates resource with calls to get, list, create, update.
      Returns:
      ServiceRates resource initialized with this FreshBooksClient
    • tasks

      public Tasks tasks()
      FreshBooks tasks resource with calls to get, list, create, update, delete.
      Returns:
      Tasks resource initialized with this FreshBooksClient
    • taxes

      public Taxes taxes()
      FreshBooks taxes resource with calls to get, list, create, update, delete.
      Returns:
      Taxes resource initialized with this FreshBooksClient
    • timeEntries

      public TimeEntries timeEntries()
      FreshBooks time entries resource with calls to get, list, create, update, delete.
      Returns:
      TimeEntries resource initialized with this FreshBooksClient