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

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.

Warning
ReportDataUri value must be url encoded, failing to correctly encode the query string parameter will result in the request failing with a 401 - Not Authorised as the OAuth signature will not match the expected.

Variable Description Required
ReportDataUri The relative url to the report run endpoint including the required query string parameters. Yes
TransformDefinitionKey For P45 as a PDF this is P45-Pdf Yes

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

curl -X GET
   https://api.test.payrun.io/ReportTransform?ReportDataUri=%2Freport%2FP45%2Frun%3FEmployerKey%3DER001%26EmployeeKey%3DEE001&TransformDefinitionKey=P45-Pdf
   -H 'Content-type: application/xml'
   -H 'Accept: application/xml'
   -H 'Api-Version: default'
   -H 'Authorization: {OAuthHeader}'
   -H 'Cache-Control: no-cache'
curl -X GET
   https://api.test.payrun.io/ReportTransform?ReportDataUri=%2Freport%2FP45%2Frun%3FEmployerKey%3DER001%26EmployeeKey%3DEE001&TransformDefinitionKey=P45-Pdf
   -H 'Content-type: application/json'
   -H 'Accept: application/json'
   -H 'Api-Version: default'
   -H 'Authorization: {OAuthHeader}'
   -H 'Cache-Control: no-cache'

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