Hi
I have a need to fill in a PDF Template before posting out to a user so I did that in my helper server which now takes a POST call with all the info and returns a personalised PDF - I did it at first in a frontend script which worked great but I need to attach the resultant pdf file to an attribute so I can then email it automatically and it turns out I cannot save the file locally to then attach to a backend email call so I have transferred the entire process to the back end where I could save the file locally and then attach it to an attribute so I can email it out to the user but I now get this error :
api failed to execute REST call POST 'http://localhost:9000/fill-form', ERROR: invalid byte sequence for encoding "UTF8": 0xe2 0xe3 0xcf (SQLSTATE 22021)
it doesn't seem to be touching my helper server but failing before even sending the request - My code is below
$BODY$
DECLARE
v_sts_accnum TEXT;
v_sts_address TEXT;
v_sts_ref TEXT;
v_sts_other_y TEXT;
v_sts_other_n TEXT;
v_sts_other_co TEXT;
v_sts_postcode TEXT;
v_sts_reason TEXT;
v_cpc_y TEXT;
v_cpc_n TEXT;
v_tach_y TEXT;
v_tach_n TEXT;
v_drv_surname TEXT;
v_drv_midname TEXT;
v_drv_forename TEXT;
v_drv_dob TEXT;
v_drv_curr_addr TEXT;
v_drv_license_addr TEXT;
v_drv_curr_pc TEXT;
v_drv_license_pc TEXT;
v_drv_dl_number TEXT;
v_drv_sig TEXT;
v_drv_date TEXT;
item JSONB;
-- request
body TEXT; -- request body (can be JSON, XML or any other text value)
headers JSONB; -- request header (every JSON key/value pair is one header)
method TEXT; -- request method (DELETE, GET, PATCH, POST, PUT)
url TEXT; -- request URL
-- request options
tls_skip_verify BOOL; -- if true request ignores SSL/TLS issues such as cert expired or bad hostname
-- callback (optional)
callback_function_id UUID; -- ID of backend function to receive response of request
callback_value TEXT; -- value to forward to callback function
BEGIN
PERFORM {omnia}.[update_debug_log]('D906 starting call : '||v_details::TEXT, 1, 'D906');
-- basics
method := 'POST';
url := 'http://localhost:9000/fill-form';
tls_skip_verify := true;
FOR item IN SELECT * FROM jsonb_array_elements(v_details::JSONB) LOOP
v_sts_accnum :=item->>'sts_accnum';
v_sts_address :=item->>'sts_address';
v_sts_ref :=item->>'sts_ref';
v_sts_other_y :=item->>'sts_other_y';
v_sts_other_n :=item->>'sts_other_n';
v_sts_other_co :=item->>'sts_other_co';
v_sts_postcode :=item->>'sts_postcode';
v_sts_reason :=item->>'sts_reason';
v_cpc_y :=item->>'cpc_y';
v_cpc_n :=item->>'cpc_n';
v_tach_y :=item->>'tach_y';
v_tach_n :=item->>'tach_n';
v_drv_surname :=item->>'drsurname';
v_drv_midname :=item->>'drv_midname';
v_drv_forename :=item->>'drv_forename';
v_drv_dob :=item->>'drv_dob';
v_drv_curr_addr :=item->>'drv_curr_addr';
v_drv_license_addr :=item->>'drv_license_addr';
v_drv_curr_pc :=item->>'drv_curr_pc';
v_drv_license_pc :=item->>'drv_license_pc';
v_drv_dl_number :=item->>'drv_dl_number';
v_drv_sig :=item->>'drv_sig';
v_drv_date :=item->>'drv_date';
END LOOP;
-- prepare request body, example JSON: { "username":"api_user", "password":"MY_STRONG_PW" }
body := jsonb_build_object(
'sts_accnum', v_sts_accnum,
'sts_address', v_sts_address,
'sts_ref', v_sts_ref,
'sts_other_y', v_sts_other_y,
'sts_other_n', v_sts_other_n,
'sts_other_co', v_sts_other_co,
'sts_postcode', v_sts_postcode,
'sts_reason', v_sts_reason,
'cpc_y', v_cpc_y,
'cpc_n', v_cpc_n,
'tach_y', v_tach_y,
'tach_n', v_tach_n,
'drv_surname', v_drv_surname,
'drv_midname', v_drv_midname,
'drv_forename', v_drv_forename,
'drv_dob', v_drv_dob,
'drv_curr_addr', v_drv_curr_addr,
'drv_license_addr', v_drv_license_addr,
'drv_curr_pc', v_drv_curr_pc,
'drv_license_pc', v_drv_license_pc,
'drv_dl_number', v_drv_dl_number,
'drv_sig', v_drv_sig,
'drv_date', v_drv_date
)::TEXT;
headers := jsonb_build_object(
'Content-Type', 'application/json'
);
-- optional: define callback function to receive the authentication response
-- the callback function can be any backend function with these 3 arguments:
-- http_status INTEGER, response TEXT, callback TEXT
callback_function_id := 'fa840c31-d029-48a2-8ce0-91c8a69762d4';
-- optional: prepare callback value, which will be available in the callback function
-- useful to forward data for a future REST call (after authentication for example)
-- this example builds the following JSON: { "key1":"value1", "key2":{ "sub_key1":"sub_value1" }, "key3":[1,2,3] }
callback_value := v_record::TEXT;
-- execute REST call
PERFORM instance.rest_call(
method,
url,
body,
headers,
tls_skip_verify,
callback_function_id,
callback_value
);
RETURN 0;
EXCEPTION
WHEN OTHERS THEN
PERFORM {omnia}.[update_debug_log]('Error occurred in generate_d906: ' || SQLERRM, 3,'D906');
RETURN -1;
END;
$BODY$