Using the Xero API with CFML


Private Application – Matthew Bryant

Xero API Private Application code sample – contributed by Matthew Bryant.

Xero.cfc –  on GitHub.com ›

This is an outline guide on how to use the Xero API with a private API application. If you have any tips or suggestions, please contribute them here and we will update our documentation.

Self-signed certificate generation

Using OpenSSL

Mac users go to the Terminal Application

Windows users download openSSL for windows

  1. openssl genrsa -out xero_privatekey.pem 1024
  2.  openssl req -newkey rsa:1024 -x509 -key xero_privatekey.pem -out xero_publickey.cer -days 365
    (The .cer will be needed when creating the API application in the Xero Developer Centre ‘Add Application’ screen)
  3.  openssl pkcs8 -topk8 -nocrypt -in xero_privatekey.pem -out xero_privatekey.pcks8
    (Extracts the private key in PKCS8 format used for signature in this cfc)

Create Xero Application from Developer Center

Use public key (.cer) generated above to create a Private Xero Application

Sample Code:

<cfsavecontent variable="xeroXML">
  <cfoutput>
    <Contacts>
      <Contact>
        <Name>ABC Limited</Name>
      </Contact>
      <Contact>
        <Name>DEF Limited</Name>
      </Contact>
    </Contacts>
  </cfoutput>
</cfsavecontent>

<cfset oXero = createObject("component", "path.to.xero.cfc.file").init( 
  privatePCKS8KeyPath="/path/to/xero_privatekey.pcks8",
  consumerKey="AABBCCDDEEFFGGHHIIJJKKLLMMNNOO") />

<cfset stResult = oXero.sendRequest( method="POST",
  endPoint="Contacts",
  xml="#xeroXML#",
  SummarizeErrors="false") >

<cfdump var="#stResult#" />

Keen to contribute a partner app example? Drop us a line and we’ll recognise your contribution here.