Introduction
Xero is a cloud based accounting program. The API for Xero makes use of OAuth 1.1 for authentication using RSA-SHA based signing.
This example channel shows how you can connect Iguana to this API. It makes use of the crypto APIs which are available in Iguana 6.0.2 and up.
For more information on Oauth 1.1 and connecting to Xero, this earlier article on the topic may be useful.
If you have any questions please contact us at support@interfaceware.com.
Tip: The code for this channel uses stores the the Xero login information (key, secret) in plain text this is not best practice.
You can use the encrypt.password.lua and store2.lua modules to store logon information in encrypted format, see the Salesforce.com Adapter for an example of how to do this.
Setup Xero [top]
- Go to xero.com and register a free account
- Login and click the “Try Demo Company” link at the bottom of the “Setup Organization” page
- In another tab go to https://api.xero.com
- Click the “My Applications” tab
- Select the “Private – just for use with my own organization” radio button
- Give the application a name such as “Iguana”
- Leave “Demo Company” selected
- Create an RSA Public/Private key pair. See https://developer.xero.com/documentation/auth-and-limits/private-applications. Follow the documentation from:
- https://developer.xero.com/documentation/api-guides/create-publicprivate-key
- We won’t need step three since Iguana uses the PEM format for keys
- Upload the X509 public certificate you created in the Creating the RSA Public/Private Keys section
- Upload the private.pem into the “other” folder of the demo channel
- Click the plus [+] next other in the project panel:
- Choose the Upload a File tab and Browse to find your private.pem file, then click Add File:
- Click the plus [+] next other in the project panel:
- Click the submit button to create the application
- You now have the required values to call the Xero APIs from Iguana. Copy over the consumer key and the consumer secret
- The script should now be able to connect to Xero and give you a list of Xero users for the Xero instance you have connected to
Using the Code [top]
- Import the OAuth 1.1 with Xero channel from the Builtin: Iguana Webservices repository
- Experiment with the code to find out how it works
- Then add the modules to your Translator project
- Copy the require statement from the channel and add it at the top of your script
Note: The twitter.api.lua module uses require to return a table
Note: The oauth.oauth.lua module uses require to return a table - Adapt the code to your own requirements
- Interactive scripting help is included for this module
This is the github code for the main module:
How it works [top]
The API for Xero makes use of OAuth 1.1 for authentication using RSA-SHA based signing.
This example channel shows how you can connect Iguana to this API. It makes use of the crypto APIs which are available in Iguana 6.0.2 and up.
More information [top]
- Source code for the main module on github
- Source code for the xero.api.lua module on github
- Source code for the oauth.oauth.lua module on github
- API documentation for net.http.parseRequest, net.http.respond, string.gsub and global.pcall
- Xero website
- Xero API reference
- This earlier Xero article may be useful