Thanks Mike for your response.
I have tried the systools function and its working fine now.
SELECT DB2XML.HTTPPOSTCLOB
('endpoint details',
CAST ('<httpHeader><header name="Content-Type" value='
!!'"application/json"/>'
!!'<header name="Authorization" value="'
!!'password"'
!!'/></httpHeader>' AS CLOB(1K)),
CAST ('{"query": "query abc{parts{name}}"}'
AS CLOB(1K))
)
FROM sysibm.sysdummy1;
Original Message:
Sent: Tue April 18, 2023 01:05 PM
From: Mike Zaringhalam
Subject: DB2 Http function HTTPPOSTCLOB
Based on the error, it seems like you don't have access to the new HTTP functions in QSYS2.
The HTTP_POST call looks like it is prepared correctly.
A quick working example of the QSYS2.HTTP_GET_VERBOSE function is as follows:
SELECT RESPONSE_MESSAGE,
RESPONSE_HTTP_HEADER
FROM TABLE(QSYS2.HTTP_GET_VERBOSE(
'https://icanhazdadjoke.com/', --URL
(VALUES JSON_OBJECT(
'header' value 'Accept,application/json'
)) --Header values
));
If that query worked, then you should be able to perform the POST using the QSYS2 function.
If the query failed, then you may need to use the HTTP functions in the SYSTOOLS library.
Aside from that, I recommend using the VERBOSE versions of the HTTP functions so that error messages are received.
To receive the error message, you will need to set "includeErrorMsg" to true in the API header.
-Mike Z
------------------------------
Mike Zaringhalam
------------------------------
Original Message:
Sent: Mon April 17, 2023 11:04 AM
From: Solairaj Jayaraj
Subject: DB2 Http function HTTPPOSTCLOB
Thanks Paolo Salvatore !
I have tried using the above functions for my request getting below error.
SQL QUERY MODIFIED LINE 1
VALUES QSYS2.HTTP_POST
('HTTPS://xxxxxxxxxxxxxxxxxxxxxxxxxx',
'{"QUERY": "QUERY TEST{PARTS{NAME}}"}',
'{"HEADER":"CONTENT-TYPE,APPLICATION/JSON"')
QUERY MESSAGES:
THE SQL STATEMENT IS NOT SUPPORTED.
*** END ***
1=Help 2=Run 3=End 4=Print 5=Chart 6=Draw
7=Backward 8=Forward 9=Form 10=Insert 11=Delete 12=Report
Since this REST api consuming process is new to me, shall you help here to clear this syntax issue.
What is the table name for above function and do we need to give any select statement. ?
I have tried verifying the same in link which you have given no luck.
Thanks.,
------------------------------
Solairaj Jayaraj
Original Message:
Sent: Fri April 14, 2023 08:11 AM
From: Paolo Salvatore
Subject: DB2 Http function HTTPPOSTCLOB
Hi Solairaj,
have you tried the new http sql function?
Values Http_Post('https://httpbin.org/post', 'your post data', '{"headers":{"accept":"application/json"}}');
Faster, NO java, use DCM for CA cert validation.
https://www.ibm.com/support/pages/node/6486889
You need at least V7R3 at certains TR level.
Bye
------------------------------
Paolo Salvatore