FreshBooks Classic Authenticate an Element Instance

You can authenticate with FreshBooks Classic to create your own instance of the FreshBooks Classic element through the UI or through APIs. Once authenticated, you can use the element instance to access the different functionality offered by the FreshBooks Classic platform.

Authenticate Through the UI

Use the UI to authenticate with FreshBooks Classic and create an element instance. When you authenticate with FreshBooks Classic via OAuth 1.0 through the UI, all you need to do is add a name for the instance. After you create the instance, you'll log in to FreshBooks Classic to authorize Cloud Elements to access your account. For more information about authenticating an element instance, see Authenticate an Element Instance (UI)

After successfully authenticating, we give you several options for next steps. Make requests using the API docs associated with the instance, map the instance to a virtual data resource, or use it in a formula template.

Authenticate Through API

FreshBooks Classic is a Finance Platform. When you provision an instance, your app will have access to the different functionality offered by the FreshBooks Classic platform.

Step 1. Get Elements OAuth Token

  • HTTP Header: None
  • HTTP Verb: GET
  • Request URL: /elements/{keyOrId}/oauth/token
  • Request Body: None
  • Query Parameters:

  • key - FreshBooks Classic

  • apiKey– - “Your Personal Subsite e.g. for mycompany.FreshBooks Classic.com would be mycompany”

  • apiSecret – the secret obtained from registering your app with the provider

  • callbackUrl – the URL that you supplied to the provider when registering your app,

  • siteAddress - your FreshBooks Classic Site Address you are wanting to Authorize e.g. for targetcompany.FreshBooks Classic.com would be targetcompany

Description: The result of this API invocation returns a requestToken and Secret from the endpoint, which are used to retrieve the redirect URL. The requestToken is used in the GET /elements/{keyOrId}/oauth/url call.

Each of the OAuth API calls will be shown below.

Example cURL Command:

curl -X GET
-H 'Content-Type: application/json'
'https://api.cloud-elements.com/elements/api-v2/elements/FreshBooks Classic/oauth/token?apiKey=insert_api_key&apiSecret=insert_api_secret&callbackUrl=https%3A%2F%2Fwww.mycoolapp.com%2Fauth&siteAddress=insert_FreshBooks Classic_site_address'

Response:

{
  "token": "qyprd1Twij60MH06lKGUZTJwx7tbzpPQx6aZnvKe0xI7",
  "secret": "KKSbL0J2wLGMqhMXTEh1ERkSx9tsIbAHUevF"
}

FreshBooks Classic expects a token and secret. These are contained in the response to the initial GET request. Please make note of the token and secret. The token is needed in the GET /elements/{keyOrId}/oauth/url call which is shown below.

Step 2. Get Elements OAuth URL

  • HTTP Header: None
  • HTTP Verb: GET
  • Request URL: /elements/{keyOrId}/oauth/url
  • Request Body: None
  • Query Parameters:

  • key - FreshBooks Classic

  • apiKey– - “Your Personal Subsite e.g. for mycompany.FreshBooks Classic.com would be mycompany”

  • apiSecret – the secret obtained from registering your app with the provider

  • callbackUrl – the URL that you supplied to the provider when registering your app,

  • requestToken - the token obtained from the GET /elements/{keyOrId}/oauth/token call (previous step).

  • siteAddress - your FreshBooks Classic Site Address you are wanting to Authorize e.g. for targetcompany.FreshBooks Classic.com would be targetcompany

Description: The result of this API invocation is an OAuth redirect URL from the endpoint. Your application should now redirect to this URL, which in turn will present the OAuth authentication and authorization page to the user. When the provided callback URL is executed, a code value will be returned, which is required for the Create Instance API.

Example cURL Command:

curl -X GET
-H 'Content-Type: application/json'
'https://api.cloud-elements.com/elements/api-v2/elements/FreshBooks Classic/oauth/url?apiKey=insert_fake_api_key&apiSecret=insert_fake_api_secret&callbackUrl=http://www.demonstrab.ly&requestToken=insert_requestToken&siteAddress=insert_FreshBooks Classic_site_address'

Response:

{
  "oauthUrl": "https://siteaddress.FreshBooks Classic.com/oauth/oauth_authorize.php?oauth_token=null&oauth_callback=https%3A%2F%2Fwww.mycoolapp.com%2Fauth%3Fstate%3DFreshBooks Classic",
  "element": "FreshBooks Classic"
}

Step 3. Create an Instance

Your application should now redirect to the oauthUrl returned in step 2, which in turn will present the OAuth authentication and authorization page to the user.

HANDLE CALLBACK FROM THE ENDPOINT

After the user successfully authenticates, the provided callback URL is executed. The callback URL will contain several parameters, listed below. These additional parameters, along with the original API key and API secret are required for the Create Instance API.

The parameters that you will need to parse from the callback URL are listed below, along with an example of what the callback URL should look like. oauth_token oauth_verifier refresh_token secret

To provision your FreshBooks Classic Element, use the /instances API.

Below is an example of the provisioning API call.

  • HTTP Headers: Authorization- User , Organization
  • HTTP Verb: POST
  • Request URL: /instances
  • Request Body: Required – see below
  • Query Parameters: none

Description: token is returned upon successful execution of this API. This token needs to be retained by the application for all subsequent requests involving this element instance.

A sample request illustrating the /instances API is shown below.

HTTP Headers:

Authorization: User <INSERT_USER_SECRET>, Organization <INSERT_ORGANIZATION_SECRET>

This instance.json file must be included with your instance request. Please fill your information to provision. The “key” into Cloud Elements FreshBooks Classic is “FreshBooks Classic”. This will need to be entered in the “key” field below depending on which Element you wish to instantiate.

{
  "element": {
    "key": "FreshBooks Classic"
  },
  "providerData": {
       "oauth_token": "<OAUTH_TOKEN_RETURNED_IN_OAUTH_EXCHANGE>",
       "oauth_verifier": "<OAUTH_VERIFIER_RETURNED_IN_OAUTH_EXCHANGE>",
       "secret": "<SECRET_RETURNED_IN_OAUTH_EXCHANGE>"
   },
  "configuration": {
    "oauth.api.key":"<INSERT_FreshBooks Classic_API_KEY>",
    "oauth.api.secret":"<INSERT_FreshBooks Classic_API_SECRET>",
    "FreshBooks Classic.site.address":"<INSERT_FreshBooks Classic_SITE_ADDRESS>"
  },
  "tags": [
    "<INSERT_TAGS>"
  ],
  "name": "<INSERT_INSTANCE_NAME>"
}

Here is an example cURL command to create an instance using /instances API.

Example Request:

curl -X POST
-H 'Authorization: User <INSERT_USER_SECRET>, Organization <INSERT_ORGANIZATION_SECRET>'
-H 'Content-Type: application/json'
-d @instance.json
'https://api.cloud-elements.com/elements/api-v2/instances'

If the user does not specify a required config entry, an error will result notifying her of which entries she is missing.

Below is a successful JSON response:

{
  "id": 123,
  "name": "Test",
  "token": "Ck9PmTdQ4WLe221gRtM0VAp2+trCYHBsEtA=",
  "element": {
    "id": 123,
    "name": "FreshBooks Classic Beta",
    "key": "FreshBooks Classic",
    "description": "Add a FreshBooks Classic Instance to connect your existing FreshBooks Classic account to the Finance Hub",
    "image": "https://pbs.twimg.com/profile_images/111898528/fb-leaf_400x400.gif",
    "active": true,
    "deleted": false,
    "typeOauth": false,
    "trialAccount": false,
    "resources": []
  },
  "provisionInteractions": [],
  "valid": true,
  "disabled": false,
  "maxCacheSize": 0,
  "cacheTimeToLive": 0,
  "configuration": {
    "base.url": "https://{site.address}/api/2.1",
    "oauth.api.secret": "FreshBooks Classic_API_SECRET",
    "site.address": "FreshBooks Classic_SITE_ADDRESS",
    "oauth.token.url": "https://siteaddress.FreshBooks Classic.com/oauth/oauth_access.php",
    "oauth.user.token.secret": "USER SECRET",
    "pagination.max": "100",
    "event.vendor.type": "webhook",
    "oauth.request.url": "https://siteaddress.FreshBooks Classic.com/oauth/oauth_request.php",
    "oauth.user.token": "USER TOKEN",
    "oauth.authorization.url": "https://siteaddress.FreshBooks Classic.com/oauth/oauth_authorize.php",
    "pagination.type": "page",
    "event.notification.callback.url": null,
    "oauth.callback.url": "https://www.mycoolapp.com/auth",
    "oauth.api.key": "FreshBooks Classic_API_SECRET",
    "event.notification.enabled": "false"
  },
  "eventsEnabled": false,
  "cachingEnabled": false,
  "traceLoggingEnabled": false
}

Note: Make sure you have straight quotes in your JSON files and cURL commands. Please use plain text formatting in your code. Make sure you do not have spaces after the in the cURL command.

Instance Configuration

The content in the configuration section or nested object in the body posted to the POST /instances or PUT /instances/{id} APIs varies depending on which element is being instantiated. However, some configuration properties are common to all elements and available to be configured for all elements. These properties are -

  • event.notification.enabled: This property is a boolean property, and determines if event reception (via webhook or polling) is enabled for the element instance. This property defaults to false.
  • event.vendor.type: When event.notification.enabled property is set to true, this property determines the mechanism to use to receive or fetch changed events from the service endpoint. The supported values are webhook and polling. Most elements support one mechanism or the other, but some like Salesforce.com support both mechanisms. This property is optional.
  • event.notification.type: This property can be used to determine how an event notification should be sent to the consumer of the element instance, in most cases your application. Currently, webhook is the only supported value for this property. This means that when an event is received by the element instance, it will get forwarded to the provided event.notification.callback.url via a webhook to you. This property is optional.
  • event.notification.callback.url: As mentioned above, the value of this property is an http or https URL to which we will post the event for consumption by your application. This property is optional.
  • filter.response.nulls: This property defaults to true, i.e., it's boolean property, and determines if null values in the response JSON should or should not be filtered from the response returned to the consuming application. By default, all null values are filtered from the response before sending the response to the consuming application.