Working with Receipts in FreshBooks

This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Receipts in FreshBooks



Overview

The following operations allow you to work with receipts. Click an operation name to see details on how to use it.

For a sample proxy service that illustrates how to work with receipts, see Sample configuration.

OperationDescription

createReceipt

Creates a receipt.

deleteReceiptDeletes a receipt.
getReceiptRetrieves a receipt.
updateReceiptUpdates a receipt.

About multipart data

Because multipart/form-data cannot be processed inside the ESB, the ESB should be in a content-unaware status. To achieve this, you configure a pass-through proxy, and then build the message from the client end and send it to the proxy.

Operation details

This section provides details on the operations.

 Creating a receipt

The createReceipt operation creates a new expense receipt. It requires a multipart/related request to be sent in the following format:

Sample Request for createReceipt
Content-Type: multipart/related;boundary = --xxxx Content-Length:xx
 
--xxxx <!--The boundary-->
 
Content-Type: application/xml; charset=utf-8
 
<?xml version="1.0" encoding="utf-8"?> 
 <request method="receipt.create">   
  <receipt>  
      <expense_id>1</expense_id>  <!-- id of expense -->  
      <image>cid:xxxxxxxxxxxxx</image> <!-- content-id used on the related binary content -->  
  </receipt>
 </request>  
 
-xxxx <!--The boundary-->

Content-Type:[image/png|application/pdf|image/jpg]
Content-Disposition : attachment : filename = "filename.png" 
content-id : <content-id>
 
<!-- INCLUDE THE FILE BINARY DATA-->
 
--xxxx <!--The boundary--> 
Related FreshBooks documentation

http://developers.freshbooks.com/docs/receipts/#receipt.create

 Deleting a receipt

The deleteReceipt operation deletes the specified receipt.

deleteReceipt
<freshbooks.deleteReceipt>
	<expenseId>{$ctx:expenseId}</expenseId>
</freshbooks.deleteReceipt>
Properties
  • expenseId: Required - The ID of the expense from which the receipt should be deleted.
Sample request

Following is a sample REST/XML request that can be handled by the deleteReceipt operation.

Sample Request for deleteReceipt
<deleteReceipt>
   <arbitraryPassword></arbitraryPassword>
   <apiUrl>https://sansu.freshbooks.com</apiUrl>
   <authenticationToken>c361a63c7456dfg519412fa8051ea605a6d</authenticationToken>
   <expenseId>170488</expenseId>
</deleteReceipt> 
Related FreshBooks documentation

http://developers.freshbooks.com/docs/receipts/#receipt.delete

 Retrieving a receipt

The getReceipt operation retrieves information for a specified receipt.

getReceipt
<freshbooks.getReceipt>
	<expenseId>{$ctx:expenseId}</expenseId>
</freshbooks.getReceipt>
Properties
  • expenseId: Required - The ID of the expense from which to retrieve the receipt.
 Sample request

Following is a sample REST/XML request that can be handled by the getReceipt operation.

Sample Request for getReceipt
<getReceipt>
   <arbitraryPassword></arbitraryPassword>
   <apiUrl>https://sansu.freshbooks.com</apiUrl>
   <authenticationToken>c361a63c74565sd19412fa8051ea605a6d</authenticationToken>
   <expenseId>170488</expenseId>
</getReceipt>
Related FreshBooks documentation

http://developers.freshbooks.com/docs/receipts/#receipt.get

Updating a receipt

The updateReceipt operation updates an existing expense receipt. It requires a multipart/related request to be sent in the following format:

updateReceipt
Content-Type: multipart/related;boundary = --xxxx Content-Length:xx
 
--xxxx <!--The boundary-->
 
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8"?>   
  <request method="receipt.update">   
    <receipt>  
        <expense_id>1</expense_id>  <!-- id of expense -->  
        <image>cid:xxxxxxxxxxxxx</image> <!-- content-id used on the related binary content -->  
    </receipt>  
</request>  
 
-xxxx <!--The boundary-->

Content-Type:[image/png|application/pdf|image/jpg]
Content-Disposition : attachment : filename = "filename.png" 
content-id : <content-id>
 
<!-- INCLUDE THE FILE BINARY DATA-->
 
--xxxx <!--The boundary--> 
Related FreshBooks documentation

http://developers.freshbooks.com/docs/receipts/#receipt.update

Sample configuration

Following is a sample proxy service that illustrates how to connect to FreshBooks with the init operation and use the getReceipt operation. The sample request for this proxy can be found in getReceipt sample request. You can use this sample as a template for using other operations in this category.

Sample Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="freshbooks_getReceipt"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <property name="arbitraryPassword" expression="//arbitraryPassword/text()"/>
         <property name="apiUrl" expression="//apiUrl/text()"/>
         <property name="authenticationToken" expression="//authenticationToken/text()"/>
         <property name="expenseId" expression="//expenseId/text()"/>
         <freshbooks.init>
            <arbitraryPassword>{$ctx:arbitraryPassword}</arbitraryPassword>
            <apiUrl>{$ctx:apiUrl}</apiUrl>
            <authenticationToken>{$ctx:authenticationToken}</authenticationToken>
         </freshbooks.init>
         <freshbooks.getReceipt>
            <expenseId>{$ctx:expenseId}</expenseId>
         </freshbooks.getReceipt>
         <filter source="$axis2:HTTP_SC" regex="^[^2][0-9][0-9]">
            <then>
               <switch source="$axis2:HTTP_SC">
                  <case regex="400">
                     <property name="ERROR_CODE" value="600400"/>
                     <property name="ERROR_MESSAGE" expression="//*[local-name()='error']"/>
                  </case>
                  <case regex="401">
                     <property name="ERROR_CODE" value="600401"/>
                     <property name="ERROR_MESSAGE" expression="//*[local-name()='error']"/>
                  </case>
                  <case regex="403">
                     <property name="ERROR_CODE" value="600403"/>
                     <property name="ERROR_MESSAGE" expression="//*[local-name()='error']"/>
                  </case>
                  <case regex="404">
                     <property name="ERROR_CODE" value="600404"/>
                     <property name="ERROR_MESSAGE" expression="//*[local-name()='error']"/>
                  </case>
                  <case regex="500">
                     <property name="ERROR_CODE" value="600500"/>
                     <property name="ERROR_MESSAGE" expression="//*[local-name()='error']"/>
                  </case>
                  <default>
                     <property name="ERROR_CODE" expression="$axis2:HTTP_SC"/>
                     <property name="ERROR_MESSAGE" expression="//*[local-name()='error']"/>
                  </default>
               </switch>
               <sequence key="faultHandlerSeq"/>
            </then>
         </filter>
         <respond/>
      </inSequence>
      <outSequence>
        <send/>
      </outSequence>
   </target>
   <description/>
</proxy>