Perl: ricerca

La chiamata  usa la funzione document_queryNell'esempio che segue i valori dei campi: : 'INTERFACE_code'; 'INTERFACE_pass'; 'user@acme.it'; 'user_pass';  sono solo di esempio e vanno sostituiti con quelli forniti da KPNQwest.

use v5.10;
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON::XS qw(decode_json encode_json);

my $SERVER_URL = 'https://docubank.kpnqwest.it/backend/v1.0/public/script/';
my $INTERFACE_CODE     = 'INTERFACE_code';
my $INTERFACE_PASSWORD = 'INTERFACE_pass';
my $USER_LOGIN         = 'user@acme.it';
my $USER_PASSWORD      = 'user_pass';
#my $USER_TOKEN         = 'fd8dfdfndfjhv87';
my $ORGANIZATION_CODE  = 'TestOrg';
my $DOCUMENT_TYPE      = 'Fatture';
my $DOCUMENT_ID        = '3b7be077be65dcaa2417cf63baa0aaba';

my $user_agent = LWP::UserAgent->new;

my $data = {
    'message_type'      => 'DOCUMENT_QUERY',
    'version'           => '1.0',
    'authentication'    => {
        'interface_code'     => $INTERFACE_CODE,
        'interface_password' => $INTERFACE_PASSWORD,
        'login'              => $USER_LOGIN,
        'password'           => $USER_PASSWORD,
        # 'token'            => $USER_TOKEN,
    },
    'organization_code' => $ORGANIZATION_CODE,
    'document_type'     => $DOCUMENT_TYPE,
    'documentdata'      => [{
        'field_name' => 'document_id',
        'operation' => 'MATCH',
        'value1' => $DOCUMENT_ID
    }]
};

my $response = $user_agent->request(
    POST $SERVER_URL,
    'Content_Type' => 'application/json',
    'Content'      => encode_json($data) );

my $parsed_response = decode_json( $response->decoded_content );

if ( $response->is_success ) {
    if (@{$parsed_response->{'rows'}} == 1) {
        my $document = $parsed_response->{'rows'}[0];
        print "Status: $document-> {'document_status'}/$document->{'document_status_detail'}\n";
        print "sending_status:\n";
        foreach my $sending_status (@{$document->{'sending_status'}}) {
            print "\t$sending_status-> {'media_type'}\t$sending_status->{'send_status'}\n";
        }
    } else {
        print "Document not found\n"
    }    
} else {
    given ( $parsed_response->{'status'} ) {
        when ('ERROR_PARSING_FIELD_QUERY') {
            # ...
        }
        when ('TOO_MANY_CLAUSES') {
            # ...
        }
        when ('REQUIRED_CAPABILITY_NOT_AVAILABLE') {
            # ...
        }
        when ('DOCUMENT_TYPE_NOT_FOUND') {
            # ...
        }
        when ('ORGANIZATION_NOT_FOUND') {
            # ...
        }
        when ('BAD_INTERFACE_CODE_PASSWORD') {
            # ...
        }
        when ('USER_AUTHENTICATION_FAILURE') {
            # ...
        }
        when ('BACKEND_SERVER_ERROR') {
            # ...
        }
        default {
            die 'Should not arrive in here'
        }
    }
}
 


Attenzione: le informazioni riportate in questa sezione possono non essere perfettamente allineate con la versione corrente del servizio, in continua evoluzione. Per qualunque informazione specifica, vi preghiamo di contattarci.