menu di navigazione del network

Perl - Come "passo" l'API KEY

Ciao.

Sto provando a scrivere del codice per IO e ho letto la documentazione:

https://developer.io.italia.it/openapi.html#section/Messages/Process-for-sending-a-message-to-a-citizen

Sto provando in perl come segue:

#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use JSON;
use Digest::MD5 qw(md5);
use Digest::SHA qw(hmac_sha256_base64);
use MIME::Base64;

my $api_key ='aaaaa';
my $api_private_key ='aaaaa';
my $ua = LWP::UserAgent->new;

my $url = "https://api.cd.italia.it/api/v1/messages/CFTEST";

my %req = (

        time_to_live => 3600,
        content => {
                subject => "Welcome new user !",
                markdown => "# This is a markdown header to show how easily markdown can be converted to **HTML** Remember: this has to be a long text.",
                payment_data => {},
                due_date => "2019-10-13T00:00:00.000Z"
        },
        default_addresses => {
                email => "andrea\@aaaaa.aaa"
        }
);

my $nonce = int(rand(1000000));
my $post_data = encode_json(\%req);
my $post_data_enc = encode_base64(md5($post_data));
my $req_signature = sprintf("%sPOST%s%s%s", $api_key, lc(urlencode($url)), $nonce, $post_data_enc);

my $req_signature_hmac = hmac_sha256_base64($req_signature, decode_base64($api_private_key));
my $auth_header_value = sprintf("amx %s:%s:%s", $api_key, $req_signature_hmac, $nonce);
my $response = $ua->post($url,
    Content => $post_data,
    'Content-Type' => 'application/json',
    'charset' => 'utf-8',
    Authorization => $auth_header_value
);

Ma dove devo passare l’api key e la subscription key?

Continua a rispondermi:
Request failed: { "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." }

Come posso fare?

Grazie.

Andrea

L’api key andava messa nell’header e non nel context.

Se qualcuno avesse bisogno del codice basta chiedere che lo scambio volentieri.

Andrea