La fonction suivante permet d'appeler une API_TEST :
Code : Tout sélectionner
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// API_TEST
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DCL-PROC API_TEST EXPORT;
Dcl-PI API_TEST ;
InClient_ID Char(30) CONST;
InClient_Secret Char(50) CONST;
InDestinataires Char(100) CONST;
InMessage Char(1000) CONST;
End-PI;
// Déclarations locales
Dcl-S Grant_Type Char(50) INZ('client_credentials') CCSID(1208);
Dcl-S L_Client_ID Char(30) INZ('') CCSID(1208);
Dcl-S L_Client_Secret Char(50) INZ('') CCSID(1208);
Dcl-S L_Destinataires Char(100) INZ('') CCSID(1208);
Dcl-S L_Message Char(1000) INZ('') CCSID(1208);
Dcl-S Body VarChar(2000) INZ('') CCSID(1208);
Dcl-S $_Select VarChar(2000) INZ('') CCSID(1208);
Dcl-S Retour VarChar(2000) INZ('');
Dcl-DS DS_Retour QUALIFIED;
Donnees VarChar(2000) ;
Message VarChar(2000);
End-DS;
// Initialisations
L_Client_ID = %TRIM(InClient_ID);
L_Client_Secret = %TRIM(InClient_Secret);
// Construction du body
L_Destinataires = %TRIM(InDestinataires);
L_Message = %TRIM(InMessage);
Body = '{"Destinataire":"' + %TRIM(L_Destinataires) + '", "Message":"' + %TRIM(L_Message) + '"}';
// Appel de l'API API_TEST
$_Select = ' WITH Token_Table AS (';
$_Select += ' SELECT access_token as access_token FROM JSON_TABLE(';
$_Select += ' SYSTOOLS.HTTPPOSTCLOB(' + G_Quote + 'UrlAuthentification' + G_Quote + ', ';
$_Select += ' CAST(' + G_Quote + '<httpHeader><header name="content-type" value="application/x-www-form-urlencoded"/></httpHeader>' + G_Quote + ' AS CLOB(1K) ),';
$_Select += G_Quote + 'grant_type=' + G_Quote + ' CONCAT SYSTOOLS.URLENCODE(' + G_Quote + %TRIM(Grant_Type) + G_Quote + ', ' + G_Quote + '' + G_Quote + ') CONCAT ';
$_Select += G_Quote + '&client_id=' + G_Quote + ' CONCAT SYSTOOLS.URLENCODE(' + G_Quote + %TRIM(L_Client_ID) + G_Quote + ', ' + G_Quote + '' + G_Quote + ') CONCAT ';
$_Select += G_Quote + '&client_secret=' + G_Quote + ' CONCAT SYSTOOLS.URLENCODE(' + G_Quote + %TRIM(L_Client_Secret) + G_Quote + ', ' + G_Quote + '' + G_Quote + ')';
$_Select += ' ),';
$_Select += G_Quote + '$' + G_Quote;
$_Select += ' Columns(';
$_Select += ' token_type varchar(20) PATH ' + G_Quote + '$.token_type' + G_Quote + ',';
$_Select += ' access_token varchar(2000) PATH ' + G_Quote + '$.access_token' + G_Quote + ',';
$_Select += ' expires_in decimal(9, 0) PATH ' + G_Quote + '$.expires_in' + G_Quote;
$_Select += ' )) AS Token';
$_Select += ' ),';
$_Select += ' Call_WebAPI AS (';
$_Select += ' SELECT';
$_Select += ' (' + G_Quote + '<httpHeader>';
$_Select += ' <header name="content-type" value="application/json"/>';
$_Select += ' <header name="Authorization" value="Bearer ' + G_Quote + ' || TRIM(access_token) || ' + G_Quote + '"/>';
$_Select += ' </httpHeader>' + G_Quote + ' ) AS Header,';
$_Select += ' CAST(' + G_Quote + %TRIM(Body) + G_Quote + ' AS VARCHAR(2000)) AS Body';
$_Select += ' FROM SYSIBM.SYSDUMMY1, Token_Table';
$_Select += ' )';
$_Select += ' SELECT CAST(SYSTOOLS.HTTPPOSTCLOB(' + G_Quote + 'URLDeMonAPI_TEST' + G_Quote;
$_Select += ', CAST(Header AS CLOB(10K)), body) AS VARCHAR(2000)) FROM Call_WebAPI';
EXEC SQL PREPARE P_API_TEST FROM :$_Select;
EXEC SQL DECLARE C_API_TEST CURSOR FOR P_API_TEST;
EXEC SQL OPEN C_API_TEST;
EXEC SQL FETCH NEXT FROM C_API_TEST INTO :Retour;
IF SqlCode <> 0;
ENDIF;
EXEC SQL CLOSE C_API_TEST;
DS_Retour = Retour;
END-PROC;
Message . . . . : Conversion de caractères entre CCSID 65535 et CCSID 1200
incorrecte.
Cause . . . . . : Une conversion de caractères a été tentée pour des données
alphanumériques incompatibles. Aucune conversion n'a été définie entre CCSID
65535 et CCSID 1200.
Si un CCSID est 65535, l'autre CCSID est un CCSID graphique. Aucune
conversion n'a été définie entre 65535 et un CCSID graphique.
La requête fonctionne pourtant dans ACS.
Quelqu'un aurait une idée ?
Jean-Marie