Generating a P45

When an employee leaves an employer's employment they are required to provide a completed form known as a P45. The P45 provides details of an employee for their next employer, most importantly it includes the amount of tax paid they have already paid in the current tax year and the code and basis upon which it was calculated. Given this information the new employer can correctly setup the employee on their payroll system and the correct tax will be calculated.

Executing the P45 report

The P45 is a system defined report in the PayRun.io API, as with all reports you can request the report in either XML or JSON format.

To execute a report you must invoke the run endpoint and pass any required variables as query string parameters.

Variable Description Required
EmployerKey The target employer's resource unique key. Yes
EmployeeKey The target employee's resource unique key. The employee must have a leaving date set. Yes

This example demonstrates how to [GET] the report P45 output.

curl -X GET \
  https://api.test.payrun.io/Report/P45/run?EmployerKey=ER001&EmployeeKey=EE001 \
  -H 'Accept: application/xml' \
  -H 'Api-Version: default' \
  -H 'Authorization: {OAuthHeader}' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-type: application/xml' \
curl -X GET \
  https://api.test.payrun.io/Report/P45/run?EmployerKey=ER001&EmployeeKey=EE001 \
  -H 'Accept: application/json' \
  -H 'Api-Version: default' \
  -H 'Authorization: {OAuthHeader}' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-type: application/json' \

Response Example

<?xml version="1.0"?>
<P45Report xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Generated="2017-12-15T18:04:44">
    <Employer>
        <Link href="/Employer/ER001/2018-04-05" />
        <Generated Day="15" Month="12" Year="2017">2017-12-15</Generated>
        <Name>P60 employer</Name>
        <TaxOfficeNumber>451</TaxOfficeNumber>
        <TaxOfficeReference>A451</TaxOfficeReference>
        <Address>
            <Address1>Address 1</Address1>
            <Address2>Address 2</Address2>
            <Address3>Address 3</Address3>
            <Address4>Address 4</Address4>
            <Postcode>TE1 1ST</Postcode>
            <Country>United Kingdom</Country>
        </Address>
        <Employee>
            <Link href="/Employer/ER001/Employee/EE001/2018-04-05" />
            <Code>EMP001</Code>
            <Title>Mrs</Title>
            <FirstName>Shirley</FirstName>
            <MiddleName>Janice</MiddleName>
            <LastName>Trotter</LastName>
            <NiNumber>JS123456B</NiNumber>
            <LeavingDate Day="05" Month="04" Year="2018">2018-04-05</LeavingDate>
            <DateOfBirth Day="19" Month="04" Year="2001">2001-04-19</DateOfBirth>
            <Gender>
                <Female>X</Female>
            </Gender>
            <Address>
                <Address1>Many Waters</Address1>
                <Address2>Bridford</Address2>
                <Address3>Exeter</Address3>
                <Address4>Devon</Address4>
                <Postcode>EX6 7JE</Postcode>
                <Country>United Kingdom</Country>
            </Address>
            <TaxSummary Week1Month1="X">
                <TaxCodeAtLeaving>1150L</TaxCodeAtLeaving>
                <TaxBasis>Week1Month1</TaxBasis>
                <Week1Month1>
                    <TaxablePay>1,500.00</TaxablePay>
                    <TaxPaid>382.35</TaxPaid>
                </Week1Month1>
                <Cumulative />
            </TaxSummary>
        </Employee>
    </Employer>
</P45Report>
{
    "P45Report": {
        "@Generated": "2017-12-15T18:09:30",
        "Employer": {
            "Link": {
                "@href": "/Employer/ER001/2018-04-05"
            },
            "Generated": {
                "@Day": "15",
                "@Month": "12",
                "@Year": "2017",
                "#text": "2017-12-15"
            },
            "Name": "P60 employer",
            "TaxOfficeNumber": "451",
            "TaxOfficeReference": "A451",
            "Address": {
                "Address1": "Address 1",
                "Address2": "Address 2",
                "Address3": "Address 3",
                "Address4": "Address 4",
                "Postcode": "TE1 1ST",
                "Country": "United Kingdom"
            },
            "Employee": {
                "Link": {
                    "@href": "/Employer/ER001/Employee/EE001/2018-04-05"
                },
                "Code": "EMP001",
                "Title": "Mrs",
                "FirstName": "Shirley",
                "MiddleName": "Janice",
                "LastName": "Trotter",
                "NiNumber": "JS123456B",
                "LeavingDate": {
                    "@Day": "05",
                    "@Month": "04",
                    "@Year": "2018",
                    "#text": "2018-04-05"
                },
                "DateOfBirth": {
                    "@Day": "19",
                    "@Month": "04",
                    "@Year": "2001",
                    "#text": "2001-04-19"
                },
                "Gender": {
                    "Female": "X"
                },
                "Address": {
                    "Address1": "Many Waters",
                    "Address2": "Bridford",
                    "Address3": "Exeter",
                    "Address4": "Devon",
                    "Postcode": "EX6 7JE",
                    "Country": "United Kingdom"
                },
                "TaxSummary": {
                    "@Week1Month1": "X",
                    "TaxCodeAtLeaving": "1150L",
                    "TaxBasis": "Week1Month1",
                    "Week1Month1": {
                        "TaxablePay": "1,500.00",
                        "TaxPaid": "382.35"
                    },
                    "Cumulative": null
                }
            }
        }
    }
}

Exporting the P45 as a PDF

The PayRun.io API supports exporting specific statutory reports into the completed HMRC formatted forms. This uses an API feature known as transforming; a specific system transform has been included for the P45.

User "Transform Definition Key" to control the PDF format

PDF output is controlled by including an additional query parameter on the report execution query string. Add "TransformDefinitionKey=P45-Pdf" to return the report in PDF format.

This example demonstrates how to [GET] the P45 report as a PDF, using the same P45 report parameters as used above.

curl -X GET \
  https://api.test.payrun.io/Report/P45/run?EmployerKey=ER001&EmployeeKey=EE001&TransformDefinitionKey=P45-Pdf \
  -H 'Accept: application/xml' \
  -H 'Api-Version: default' \
  -H 'Authorization: {OAuthHeader}' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-type: application/xml' \
curl -X GET \
  https://api.test.payrun.io/Report/P45/run?EmployerKey=ER001&EmployeeKey=EE001&TransformDefinitionKey=P45-Pdf \
  -H 'Accept: application/json' \
  -H 'Api-Version: default' \
  -H 'Authorization: {OAuthHeader}' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-type: application/json' \

The response from a successful transform request will always be a binary stream with a mime-type of application/pdf.