Sign in to PrePAN

WebService::HMRC Interact with the UK HMRC tax authority Making Tax Digital API



    use WebService::HMRC::Request;
    my $r = WebService::HMRC::Request->new({
        base_url    => '',
        api_version => '1.0',

    # get from open endpoint
    my $response = $r->get_endpoint({
        endpoint => '/hello/world',
    print $response->data->{message} if $response->is_success;

    # get from application-restricted endpoint
    my $response = $r->get_endpoint({
        endpoint => '/hello/application',
        auth_type => 'application',
    print $response->data->{message} if $response->is_success;

    # get from user-restricted endpoint
    my $response = $r->get_endpoint({
        endpoint => '/hello/user',
        auth_type => 'user',
    print $response->data->{message} if $response->is_succes

    # post data as json to an application-restricted endpoint
    my $data = {serviceNames => ['mtd-vat']};
    my $response = $r->post_endpoint_json({
        endpoint => '/create-test-user/organisations',
        data => $data,
        auth_type => 'application',
    print $response->data->{userId} if $response->is_success;

    # refresh access token


This is a base set of modules used for interacting with the HMRC Making Tax Digital (MTD) and Making Tax Digital for Business (MTDfB) APIs.

HMRC is the UK government tax authority. Their APIs provide a means to submit and query information relating to personal and business tax and customs affairs.

The top-level WebService::HMRC module is a stub bundling the following modules which encapsulate the minimum functionality needed to interact with the HMRC API:

  • WebService::HMRC::Request
  • WebService::HMRC::Response
  • WebService::HMRC::Authenticate

These base modules will normally not be used directly by an application. Instead, applications will generally use a higher-level module which inherits from these classes.

I have written and intend to release separately the following modules which use the base functionality:

  • WebService::HMRC::VAT
  • WebService::HMRC::HelloWorld
  • WebService::HMRC::CreateUser

Further APIs exist for different aspects of personal and company taxation. It is hoped that this base distribution makes it easier to contribute modules for these.

More information on the HMRC APIs here:


Please sign up to post a review.