I am trying to learn how to use the Mojolicious framework for Perl. I am attempting to register a callback URL with a REST service and save the RequestID returned by the REST service. I successfully get back the request but can't decode the individual values that are part of the hash.
I have the following code:
use Mojo::UserAgent;
use Mojo::Message::Response;
use Mojo::JSON;
use Mojo::Promise;
use Mojo::Content::MultiPart;
my $requestURL = "http://localhost:31297/api/CallBack/RegisterCallBackURL?";
$requestURL = $requestURL."CallBackURL=http://localhost:8081/status";
$requestURL = $requestURL."&VerboseFlag=false";
$requestURL = $requestURL."&api-version=1.2";
my $Acknowledged = "";
my $VerboseInfo = "";
my $CallBackURL = "";
my $RequestID = "";
my $CurrentJobStatus = "";
my $TimeStampReceived = "";
my $ua = Mojo::UserAgent->new;
my $tx = $ua->post($requestURL,
form => {
"Acknowledged" => $Acknowledged,
"VerboseInfo" => $VerboseInfo,
"CallBackURL" => $CallBackURL,
"RequestID" => $RequestID,
"CurrentJobStatus" => $CurrentJobStatus,
"TimeStampReceived" => $TimeStampReceived
});
my $res = $tx->result;
if ($res->is_success)
{
print "success";
print $res->message;
print $res->body;
print $RequestID;
}
else
{
print "Error";
print $res->message;
}
I get back the following response, but the individual variables do not contain data.
Process started (PID=5440) >>>
successOK{"Acknowledged":false,"VerboseInfo":false,"CallBackURL":"http://localhost:8081/status","RequestID":"98d8df79-6897-4716-8084-ee756d16a1bf","CurrentJobStatus":null,"TimeStampReceived":"2023-06-29T04:44:03.2440429-07:00"}<<< Process finished (PID=5440). (Exit code 0)
================ READY ================
You have received a JSON response (which you can see in
$res->body). You need to decode that response (using Mojo::JSON) and then extract the individual data items into your variables.