restful api call using plperl language in postgresql

189 Views Asked by At

I have install plperl language in postgresql for the purpose of sending restful api requests to an API endpoint using a function. My function is below

CREATE OR REPLACE FUNCTION sdpmtn_mt.sendnotification(
)
RETURNS text
LANGUAGE 'plperl'
COST 100
VOLATILE SECURITY DEFINER PARALLEL UNSAFE
AS $BODY$
plperl.on_init='require REST::Client';
use REST::Client;
use Encode qw(encode);
my $client = REST::Client->new(); 
$client->getUseragent()->proxy( 'https', 'https://xdmactive.maxarmdm.com:8443//test    /test'); -- # use4 proxy authentication
$client->addHeader('Content-Type', 'application/json');  --   # headers
$client->addHeader('Api-Key', '9Yw_jmh.ey3rUlkzjsdueliokT1A_kh');  # headers
$client->GET('https://xdmactive.maxarmdm.com:8443/semarchy/api/rest/query/test/test'); -- # encoding
return $client->responseContent(); 
$BODY$;

ALTER FUNCTION sdpmtn_mt.sendnotification()
OWNER TO postgres;

and the error is

ERROR: Can't modify constant item in scalar assignment at line 2, at EOF BEGIN not safe after errors--compilation aborted at line 3. CONTEXT: compilation of PL/Perl function "sendnotification" SQL state: 42601

1

There are 1 best solutions below

0
On

plperl.on_init is a PostgreSQL config parameter, not a Perl variable. You would set it in the PostgreSQL.conf file.