Here's how Google Gemini rewrites it! Haven't tried this ... AI can be silly ... but .. FWIW YMMV π
/free
// 1. Generate the Base64 string
// The SQL engine handles the conversion from EBCDIC to UTF-8 for the encode
exec sql
set :base64 = QSYS2.BASE64_ENCODE(trim(:clientid) || ':' || trim(:clientsc));
// 2. Setup the stream file for the response
replystmf_Name = '/dfreeman/upu178h305rm.txt';
replystmf_NL = %len(%trimr(replystmf_name));
replystmf_FO = SQFOVR;
// 3. Execute the POST correctly
Exec Sql
VALUES QSYS2.HTTP_POST(
-- Parameter 1: The URL
'https://wwwcie.ups.com/security/v1/oauth/token',
-- Parameter 2: THE HEADERS (Must include "Basic " prefix)
-- We CAST to CCSID 1208 (UTF-8) to ensure the API receives valid text
CAST('{"Headers":{' ||
'"Authorization":"Basic ' || :base64 || '",' ||
'"x-merchant-id":"AAAAAA",' ||
'"Content-Type":"application/x-www-form-urlencoded"' ||
'}}'
AS VARCHAR(1000) CCSID 1208),
-- Parameter 3: THE BODY (Required for OAuth token requests)
CAST('grant_type=client_credentials' AS VARCHAR(100) CCSID 1208)
)
INTO :replystmf;
/end-free