This is a Groovy script to pull payroll data from MyPAYE and use
it to create a journal and optionally a set of bank transactions in the
QuickFile accounting package. The MyPAYE API is documented
here (PDF),
it's fairly straightforward if a bit clunky, and has a couple of weird things (like the payload
you POST
has to be XML but the Content-Type
has to be form-urlencoded...) but it wasn't
too difficult for me to get working.
There's a few hard-coded nominal codes in there but I think they are ones that should be consistent across all QuickFile accounts (7000 for gross wages, 7006 for Employer NI, etc.).
The script expects another config file in the same folder called config.groovy
with the
API credentials and a few other settings for both the QuickFile and MyPAYE sides.
- A Java runtime environment version 8 or later (if you don't already have one installed I recommend Zulu JDK)
- Groovy version 2.5.x or earlier (the
httpbuilder
library I'm using doesn't work with Groovy 3 or later, one day I may have reason to update it but that day is not yet)
You need to be able to run the groovy
command from your command prompt/terminal/whatever it is called on your computer - how to do this varies from computer to computer, it may mean adding the groovy-<version>/bin
folder to your PATH environment variable, or creating a symbolic link into a directory that is already on the PATH.
Create an empty folder, and save the three .groovy
files from this Gist into that.
The script needs access to both the QuickFile and MyPAYE APIs. For the QuickFile side you need to create an "app" with appropriate permissions:
- Go to "account settings" -> "3rd party integration" -> "API"
- Create a new app, give it a meaningful name like "MyPAYE integration"
- Select
Invoices.Journal_Create
andInvoices.Bank_CreateTransaction
(the latter is only required if you want the script to generate bank transactions for the payment of net wages) in the left hand list and "add selected" to move them to the right hand list - Save the app, go back to the list of apps
- Copy the "account API key" from above the list of apps, the "app ID" (click the blue question mark button) from the app you just created and the "account" number from the top right corner of the screen and paste them into your
config.groovy
in the appropriate slots in thequickfile { ... }
section
If you want the script to create bank transactions for the payment of wages, set bankTransactions
to 'single'
(one entry for the total net wages) or 'split'
(one entry for each employee), and if your main current account is not nominal code 1200 then edit the bankNominal
appropriately. If you do not want the script to create bank transactions then set it to banktransactions = 'none'
, in which case the bankNominal
setting is ignored.
Finally set periodType
to 'W'
if you run your payrolls weekly/fortnightly/four-weekly, or 'M'
if monthly.
On the MyPAYE side you need to:
- Go to "Employer" -> "Integration"
- Tick "Enable XML Web Service Access to MyPAYE", click "update"
- Copy the "XML Web Access ID" as the
linkId
setting inconfig.groovy
- Copy the "XML Web Access Password" as the
linkPwd
Also set the taxYear
setting appropritately. The final key parameter payrollId
is not something that can be found in the MyPAYE web interface, we must use the ListPayrolls.groovy
script to find it. Save the current version of config.groovy
, then open a terminal/command prompt and run
groovy ListPayrolls.groovy
This will print a list of your MyPAYE payrolls (there is probably only one of them) along with the payroll ID for each - copy the relevant ID to the payrollId
setting in config.groovy
and save it again. You are now ready to process your payrolls.
The ProcessPayroll.groovy
script has a few hard-coded nominal codes which need to match the ones you are using in MyPAYE for certain things to be picked up correctly. In MyPAYE go to "Employer" -> "Nominal Codes" and make sure you have the following settings:
- Default payroll cost 7000
- Employer's NIC cost 7006
- Employer pension contribution cost 7007
- PAYE due & NIC due both 2210
- Default net due 2220
- Pension payments due 2230
If you use different codes for any of these in your QuickFile you will need to edit ProcessPayroll.groovy
appropriately, and change them in MyPAYE to match.
With everything set up, regular usage is very simple - on each pay day, after running your payroll, open a command line in the appropriate folder and run
groovy ProcessPayroll.groovy 1
The number argument at the end should be the tax week or month number of the payroll run you want to import into QuickFile. The script will pull the payroll data from MyPAYE and construct a journal for QuickFile. It will print the journal details for you to double-check, if you're happy with it then enter y
and the journal (and optionally the bank transactions) will be pushed into QuickFile.
If you run the payroll before payday then note that while it is possible to create journals in QuickFile that are dated in the future it is not possible to create future-dated bank transactions - if you have bankTransactions = 'none'
then you can run the ProcessPayroll
script at any time after running the payroll in MyPAYE and it will create a forward-dated journal for the pay date, but if the script is creating transactions then it can only be run on or after the actual pay date.